I have multiple .csv files in a folder with different suffix . For eg :
Data_Software
Data_Hardware
Data_Manufacturing ....
While I wouldn't advise, I might do something like:
library(data.table) # need for fread and :=
# Get a list of all files in the directory
my_dir <- "my_path_here"
FILES <- list.files(path = my_dir, pattern="*.csv$", full.names = TRUE, recursive = FALSE)
# Read every file
lapply(FILES, function(x) { assign(gsub(paste0(my_dir,"/|\\.csv$|Data_"),"",x),fread(x, header = T)[, Type := gsub(paste0(my_dir,"/|\\.csv$|Data_"),"",x)], envir = .GlobalEnv)})
This creates a table for each csv - the table is named the same name as the file, stripping the extension, path, and Data_
. It also creates a column with the table name on read