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
#' 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