[英]How to rename multiple .RDS files in RStudio
I am trying to load and rename several Ggplot graphs saved as .rds
我正在尝试加载和重命名保存为.rds
几个 Ggplot 图
The below code works fine but it gives the additional suffix .rds
to the variables that I do not need.下面的代码工作正常,但它为我不需要的变量提供了额外的后缀.rds
。
I would like the variables loaded in the R environment named as ggplot_graph1
and not ggplot_graph1.rds
我想要在 R 环境中加载的变量命名为ggplot_graph1
而不是ggplot_graph1.rds
Objects_Selected <- list.files(pattern = ".rds")
lst1 <- lapply(Objects_Selected, function(RDS_File) {
temp_file <- readRDS(RDS_File)
})
# Objects_Selected <- gsub(".rds", "", Objects_Selected)
for(RDS_File in Objects_Selected){
temp_file <- readRDS(RDS_File)
assign(RDS_File, temp_file)
}
@MrFlick thanks a lot ! @MrFlick 非常感谢!
This is the correct answer:这是正确答案:
Objects_Selected <- list.files(pattern = ".rds")
lst1 <- lapply(Objects_Selected, function(RDS_File) {
temp_file <- readRDS(RDS_File)
})
# Objects_Selected <- gsub(".rds", "", Objects_Selected)
for(RDS_File in Objects_Selected){
temp_file <- readRDS(RDS_File)
assign(gsub("\\.rds$", "", RDS_File), temp_file)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.