[R] persisting complex R objects

Martin Maechler maechler at stat.math.ethz.ch
Mon Sep 20 13:16:10 CEST 2004


>>>>> "Richard" == Richard Mott <rmott at well.ox.ac.uk>
>>>>>     on Mon, 20 Sep 2004 12:00:49 +0100 writes:

    Richard> Is there a method to save a large and complex R
    Richard> object (either as a binary or text file) so that it
    Richard> can be loaded and reused at a later time?
    Richard> Specifically, I am creating large lists (several
    Richard> thousand elements), each element of which is either
    Richard> a vector or a matrix (with ~ 2000 rows). The
    Richard> dimensions of the matrices are not all the same. My
    Richard> ideal would be a set of functions of the form

    Richard> obj <- create() # computes  the object
    Richard> save(obj,filename)
    Richard> obj <- load(filename)

that sounds alright.
I'd use 
    save(*, filename,  compress = TRUE)
                       ^^^^^^^^^^^^^^^
if dealing with largish objects.

Also note that
     attach(filename)
is an alternative that may be a bit cleaner for your situation
that's probably not used enough.

Regards,
Martin Maechler




More information about the R-help mailing list