Last active
November 19, 2019 23:00
-
-
Save aetiologicCanada/c72b641e4b855f37d23d94781545657b to your computer and use it in GitHub Desktop.
R/tidyverse read multiple files into one large df
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
library(tidyverse) | |
library(fs) | |
# Let us make some fake data | |
fs::dir_create("data") | |
makesomefiles <- tibble( | |
path= paste0("data/", LETTERS, ".dummytxt") | |
) | |
makesomefiles | |
# make some content for these files | |
sometext <- tibble(text="Hi there2") | |
walk2(sometext$text, makesomefiles$path, write_lines) | |
read_massive <-function(filename) { | |
junk <- readr::read_lines(file = filename) %>% | |
tibble( | |
filename_reference = filename | |
) | |
return(junk) | |
} | |
listoffiles <- dir_info(here::here("data")) %>% filter(str_detect(path, "dummytxt")) | |
#listoffiles$path | |
content1 <- map(listoffiles$path, read_massive) %>% map_df(bind_rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment