Last active
May 30, 2023 15:49
-
-
Save jarad/8f3b79b33489828ab8244e82a4a0c5b3 to your computer and use it in GitHub Desktop.
Function to read a directory worth of data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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