narges
October 11, 2022, 4:46am
1
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!
narges
October 11, 2022, 2:55pm
2
library(here)
file_paths <- list.files(path = here::here("full.path.of.directory/"), 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]))
}
system
Closed
November 1, 2022, 2:55pm
3
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.