import multiple .rds files from the same directory in R, using "for loop"

I am going to import 125 .rds files (not reading as a list, and I am no plan to bind them) as .rds files in R.
I wrote a for loop, however it doesn't work:

######getting paths/files/file names with no extention
file_paths <- list.files(path = here::here("~/folder"), pattern = "\.rds", full.names = TRUE)
files <- dir(pattern = "*.rds")
file_names <- gsub(pattern = "\.rds$", replacement = "", x = basename(file_paths))

for loop for reading .rds files

for (i in 1:length(file_names)){
files[i] <- readRDS( file_paths[i])

Thank you!


file_paths <- list.files(path = here::here(""), pattern = "\.rds", full.names = TRUE)
file_names <- gsub(pattern = "\.rds$", replacement = "", x = basename(file_paths))

for(i in 1:length(file_names)){
assign( file_names[i],readRDS(file_paths[i]))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.