determining name of object loaded in R

后端 未结 3 1322
滥情空心
滥情空心 2021-02-02 16:55

Imagine you have an object foo that you saved as saved.file.rda as follows:

foo <- \'a\'
save(foo, file=\'saved.file.rda\')
<         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 17:33

    Assuming there is only one object saved in saved.file.rda, about:

    bar <- load('saved.file.rda')
    the.object <- get(bar)
    

    or just:

    bar <- get(load('saved.file.rda'))
    

    If you want to be "neat" and not pollute your global workspace with the stuff you loaded (and forgot the name of), you can load your object into an environment, and specify that environment in you call to get.

    Maybe:

    temp.space <- new.env()
    bar <- load('saved.file.rda', temp.space)
    the.object <- get(bar, temp.space)
    rm(temp.space)
    ...
    

提交回复
热议问题