簡體   English   中英

如何在 RStudio 中重命名多個 .RDS 文件

[英]How to rename multiple .RDS files in RStudio

我正在嘗試加載和重命名保存為.rds幾個 Ggplot 圖
下面的代碼工作正常,但它為我不需要的變量提供了額外的后綴.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 非常感謝!
這是正確答案:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM