Skip to content

Instantly share code, notes, and snippets.

@jarad
Last active May 30, 2023 15:49
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Function to read a directory worth of data
# From https://gist.github.com/jarad/8f3b79b33489828ab8244e82a4a0c5b3
library("dplyr")
library("tidyr")
library("readr")
read_my_csv = function(f, into) {
readr::read_csv(f) %>%
dplyr::mutate(file = f) %>%
tidyr::separate(file, into)
}
read_my_dir = function(path, pattern, into) {
files = list.files(path = path,
pattern = pattern,
recursive = TRUE,
full.names = TRUE)
plyr::ldply(files, read_my_csv, into = into)
}
# Above from https://gist.github.com/jarad/8f3b79b33489828ab8244e82a4a0c5b3
####################################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment