I am looking for a way to quickly read and merge a bunch of data files using the data.table fread and rbindlist functions. I think that if fread can take a vector of file names as an argument, it could be one elegant string, like
mergeddata = rbindlist(fread(list.files("my/data/directory/")))
but since this does not look like an option, I took a more inconvenient approach to navigating through files, to read them and assign them to temporary names, and then compile a list of temporary data table names created. However, I get a crash when I try to call a list of data.table names. So my questions are: (1) how can I pass a list of data names to rbindlist in this context, and (2) in a broader sense, is there a better approach to this problem?
Thanks in advance for your time and help!
datafiles = list.files()
datatablelist = c()
for(i in 1:length(datafiles)){
assign(paste("dt",i,sep=""),fread(datafiles[1]))
datatablelist = append(datatablelist ,paste("dt",i,sep=""))
}
mergeddata = rbindlist(list(datatablelist))