How to load a folder consisting of folders in R, for windows?
I have various text files in each sub-folder, all of which I want to load in one-go. Please suggest a convenient and easy method.
Thank you.
How to load a folder consisting of folders in R, for windows?
I have various text files in each sub-folder, all of which I want to load in one-go. Please suggest a convenient and easy method.
Thank you.
I am assuming that by "upload" you mean "load into R
". There are several ways to do this, below are two.
Note that the first step is having the correct list of files with full path (or be working in the appropriate wd
)
# Get the list of files
#----------------------------#
folder <- "path/to/files"
fileList <- dir(folder, recursive=TRUE) # grep through these, if you are not loading them all
# use platform appropriate separator
files <- paste(folder, fileList, sep=.Platform$file.sep)
# Load them in
#----------------------------#
# Method 1:
invisible(sapply(files, source, local=TRUE))
#-- OR --#
# Method 2:
sapply(files, function(f) eval(parse(text=f)))