How to save() with a particular variable name

后端 未结 5 773
花落未央
花落未央 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: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.

提交回复
热议问题