# R script to merge multiple CSV files within a folder.
# Replace [PATH] with the path to the folder that contains the CSV files. You can specify a different output path if necessary.
#
# Author: Luca Le Blanc
# Date: 01.11.2025

# set path
mypath <- ("[PATH]")

# install and load library
install.packages("data.table")
library(data.table)

# get a list of all files in directory named with a key word, in this case of all `.csv` files.
filenames <- list.files(mypath, pattern="*.csv", full.names=TRUE)

# read and row bind all data sets
data <- rbindlist(lapply(filenames,fread))

# write the new CSV file to a certain path and with a certain name
write.csv(data, file = "[PATH]/xyz_merged.csv")

print("done")