How to save() with a particular variable name

后端 未结 5 752
花落未央
花落未央 2020-12-01 03:02

I am repeatedly applying a function to read and process a bunch of csv files. Each time it runs, the function creates a data frame (this.csv.data) and uses save

相关标签:
5条回答
  • 2020-12-01 03:36

    My preference is to avoid the name in the RData file on load:

    obj = local(get(load('myfile.RData')))
    

    This way you can load various RData files and name the objects whatever you want, or store them in a list etc.

    0 讨论(0)
  • 2020-12-01 03:37

    you can use

    save.image("myfile.RData")
    
    0 讨论(0)
  • 2020-12-01 03:42

    Just name the arguments you use. With your code the following works fine:

    save(list = this.csv.data$unique_tag, file=saved_file_name)
    
    0 讨论(0)
  • 2020-12-01 03:43

    You really should use saveRDS/readRDS to serialize your objects. save and load are for saving whole environments.

    saveRDS(this.csv.data, saved_file_name)
    # later
    mydata <- readRDS(saved_file_name)
    
    0 讨论(0)
  • 2020-12-01 03:50

    This worked for me:

    env <- new.env()
    env[[varname]] <- object_to_save
    save(list=c(varname), envir=env, file='out.Rda')
    

    You could probably do it without a new env (but I didn't try this):

    .GlobalEnv[[varname]] <- object_to_save
    save(list=c(varname), envir=.GlobalEnv, file='out.Rda')
    

    You might even be able to remove the envir variable.

    0 讨论(0)
提交回复
热议问题