determining name of object loaded in R

后端 未结 3 1320
滥情空心
滥情空心 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:44

    well, i do know a function that eliminates the need to do that (i.e., find the name of the object in the R binary file you just loaded)--in other words, you can use this technique to load R binary files instead of 'load':

    file_path = "/User/dy/my_R_data/a_data_set.RData"
    attach(file_path, pos=2, name=choose_a_name, warn.conflict=T)
    
    • 'warn.conflicts=T' is the default option

    • 'pos=2' is also the default; "2" refers to the position in your search path. For instance, position 1 is ".GlobalEnv." To get the entire array of search paths, use search(). So you would access the search path for the new object by search()[2]

    • use 'detach' to remove the object

提交回复
热议问题