I have numerous csv files in multiple directories that I want to read into a R tribble or data.table. I use \"list.files()\" with the recursive argument set to TRUE to creat
The tidyverse provides an eloquent solution. I like to use the full file-path as the filename (which can later be truncated, if desired).
An example loading .csv files:
library(tidyverse); library(fs)
data_dir <- path("file/directory")
data_list = fs::dir_ls(data_dir, regexp = "\\.csv$")
my_data = data_list %>%
purrr::map_dfr(read_csv, .id = "source")
my_data_renamed <- my_data %>%
dplyr::mutate(source = stringr::str_replace(source, "text-to-replace", "new-text"))
#where source is the renamed file-source column