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

后端 未结 4 618
再見小時候
再見小時候 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:00

    Since this question has just been referenced let's clarify two things:

    1. attach() simply calls load() so there is really no point in using it instead of load

    2. if you want selective access to prevent masking it's much easier to simply load the file into a new environment:

      e = local({load("foo.RData"); environment()})
      

      You can then use ls(e) and access contents like e$x. You can still use attach on the environment if you really want it on the search path.

    FWIW .RData files have no index (the objects are stored in one big pairlist), so you can't list the contained objects without loading. If you want convenient access, convert it to the lazy-load format instead which simply adds an index so each object can be loaded separately (see Get specific object from Rdata file)

提交回复
热议问题