Skip to content

Instantly share code, notes, and snippets.

View odoublewen's full-sized avatar

Owen Solberg odoublewen

View GitHub Profile
@odoublewen
odoublewen / read_multiple_files.R
Last active August 2, 2019 19:51
read multiple csv or txt files, adding filename as a column, using data.table vs tidyverse
dirname = 'path/to/files'
files = list.files(dirname, pattern = "*_data.txt")
# tidyverse approach
library(tidyverse)
data = tibble(filename=files) %>%
mutate(file_contents=map(filename, ~ read_tsv(file.path(dirname, .)))) %>%
unnest()
# data.table approach