Skip to content

Instantly share code, notes, and snippets.

Last active February 6, 2017 13:35
  • Star 0 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
What would you like to do?
#' I often have individual speaker data files in a nested directory structure.
#' But I also often want to read all speaker's data into R in one big data frame.
#' Here's my current best recipe.
#' glob for the file list. This is dependent on good directory naming practices
all_files <- Sys.glob("path/speakerid*/*.csv")
df <- data_frame(file = all_files) %>% # make a column of all of the file paths
mutate(data = map(file, read.csv)) %>% # map read.csv to create a list column of dataframes
unnest(data) %>% # pop out the data into a big data frame
mutate(file = basename(file)) # keep just the basename of the file for ID.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment