At the beginning of a script I am loading all available data.frames as follows (source):
temp = list.files(pattern="*.Rds")
for (i in 1:length(temp)) assign(temp[i], readRDS(temp[i]))
However, loaded data frames inherit the extension (i.e, .Rds). I would like to strip the .Rds from the data.frame names (for efficiency's sake, before they are created).
Here, I found that I could use the following code: stripExtension <- gsub('.Rds', "", temp). However, inserted between the 2 lines of code above, the data frames are not loaded because the extension is missing:
temp = list.files(pattern="*.Rds")
stripExtension <- gsub('.Rds', "", temp)
for (i in 1:length(stripExtension)) assign(stripExtension[i], readRDS(stripExtension[i]))
My question:
- How can I load multiple .Rdsfiles at once and give them another name than the file name it originated from (i.e., the.Rdsfilename, but without the.Rdsextension)?
Any help highly appreciated.
System used:
- R version: 4.1.1 (2021-08-10)
- RStudio version: 1.4.1717
- OS: macOS Catalina version 10.15.7
 
     
    