0

I have a folder with several rda files, and want to load all of them. I have tried with:

file_list<-list.files("~/my_data/", full.names = TRUE)
walk(file_list, load)

and I get nothing.

I've also tried with map and lapply, and I get a list with the names of the objects in each rda file. What I'm doing wrong?

VicPG
  • 1
  • Do you have same object names within each Rda file? If yes, you will only see objects from the last rda file. – zx8754 Aug 01 '22 at 10:12
  • Related post using base: https://stackoverflow.com/questions/3764292/loading-many-files-at-once – zx8754 Aug 01 '22 at 10:16

2 Answers2

2

We need to load the rda files to the global environment (by default, inside walk, the rda files are read to the parent environment):

file_list <- list.files("~/my_data/", full.names = TRUE)
walk(file_list, ~ load(.x, .GlobalEnv))
PaulS
  • 21,159
  • 2
  • 9
  • 26
0

Have you tried something like this. It will create a list with all the files you have in the selected folder. Then add to the file name the path so that the load function can access the file. load them all thanks to a loop

path<- "mydata/"#where your data is

file_list <- list.files(path) #list of file names
file_list <- paste0(path,file_list) #adding to the file name, the path to get it

#loading files
for (i in 1:length(file_list)){
  load(file_list[i])
}