Skip to content
Prev 307570 / 398506 Next

append for .Rdata?

On Tue, Oct 9, 2012 at 10:35 AM, Jessica Streicher
<j.streicher at micromata.de> wrote:
I'm not sure I completely understand the issues you're trying to work
around, but I have two ideas for you.  One is a simple pseudo-append
function that loads the entire contents, adds the object, and saves
the result.  There are obviously memory issues with this strategy.

appendRData <- function(robj, filename) {

  tmpEnv <- new.env()

  savedObjects <- load(filename, envir = tmpEnv)

  # quick check for name collisions
  stopifnot(!(deparse(substitute(robj)) %in% savedObjects))

  save(list = c(savedObjects, deparse(substitute(robj))),
      file = filename,
      envir = tmpEnv)
}

A second possibility is to convert your RData files to a lazy-load
database as described by Simon Urbanek here:

http://stackoverflow.com/questions/8700619/get-specific-object-from-rdata-file
http://stackoverflow.com/questions/6550510/examining-contents-of-rdata-file-by-attaching-into-a-new-environment-possible

HTH


James