Examining contents of .rdata file by attaching into a new environment - possible?

后端 未结 4 614
再見小時候
再見小時候 2021-01-31 22:48

I am interested in listing objects in an RDATA file and loading only selected objects, rather than the whole set (in case some may be big or may already exist in the environment

4条回答
  •  梦如初夏
    2021-01-31 23:11

    I just use an env= argument to load():

    > x <- 1; y <- 2; z <- "foo"
    > save(x, y, z, file="/tmp/foo.RData")
    > ne <- new.env()
    > load(file="/tmp/foo.RData", env=ne)
    > ls(env=ne)
    [1] "x" "y" "z"
    > ne$z
    [1] "foo"
    > 
    

    The cost of this approach is that you do read the whole RData file---but on the other hand that seems to be unavoidable anyway as no other method seems to offer a list of the 'content' of such a file.

提交回复
热议问题