Skip to content

Instantly share code, notes, and snippets.

@JoFrhwld
Last active February 6, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoFrhwld/c9c465b4c01b5dd9543ae3f923a8510a to your computer and use it in GitHub Desktop.
Save JoFrhwld/c9c465b4c01b5dd9543ae3f923a8510a to your computer and use it in GitHub Desktop.
#' 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.
library(tidyverse)
#' 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