load multiple .rdata files at once

159 Views Asked by At

I'd like to load multiple .Rdata files into R with a single code line. I came across a bunch of threads on this forum that provides solutions on how to do this. But all the solutions assume that the working directory is the same as where the files are saved. In my case, the files I'd like to load are in a subfolder of the working directory, hence I get an error returned when trying to run the code stating that there's no such file or directory. Below is the code that i tried with error message:

file_list <- list.files("data files", pattern = "rp.")

lapply(file_list,load,.GlobalEnv)

Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
In addition: Warning message:
In readChar(con, 5L, useBytes = TRUE) :
  cannot open compressed file 'rp.depth.RData', probable reason 'No such file or directory'

Any advice on how to adapt the below code is greatly appreciated.

0

There are 0 best solutions below