Skip to content

Instantly share code, notes, and snippets.

@jarad jarad/read_my_dir.R
Last active May 31, 2020

Embed
What would you like to do?
Function to read a directory worth of data
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.