How can I load an object into a variable name that I specify from an R data file?

前端 未结 7 2094
你的背包
你的背包 2020-11-28 19:50

When you save a variable in an R data file using save, it is saved under whatever name it had in the session that saved it. When I later go to load it from anot

相关标签:
7条回答
  • 2020-11-28 20:53

    You can create a new environment, load the .rda file into that environment, and retrieve the object from there. However, this does impose some restrictions: either you know what the original name for your object is, or there is only one object saved in the file.

    This function returns an object loaded from a supplied .rda file. If there is more than one object in the file, an arbitrary one is returned.

    load_obj <- function(f)
    {
        env <- new.env()
        nm <- load(f, env)[1]
        env[[nm]]
    }
    
    0 讨论(0)
提交回复
热议问题