[Rcpp-devel] R CMD BATCH - segfault (was: Create and access several instances of a C++ class from R)

Christian Gunning xian at unm.edu
Tue May 24 02:37:08 CEST 2011

On Mon, May 23, 2011 at 3:00 AM,
<rcpp-devel-request at r-forge.wu-wien.ac.at> wrote:
> Just to get that clearly: Whatever I do with a C++ class in one session will be lost after quit? So, that would mean, to save my current work (done with an Rcpp module class) requires me to write a representation of the c++ object in R, which can be saved and which, after reload, rebuilds the last state of R affairs? Guessing that, my conclusion would be to not expose the Rcpp module class, rather to build an R class which rests upon the C++ stuff and holds the important information. That in turn would mean almost double use of memory? Or how would you recommend to work around?

If I understand correctly, when Douglas says "save the worksheet" he's
referring to save.image(), which by default is the equivalent of what
happens with quit(save="yes"), which is also equivalent to running R
in BATCH mode without the --no-save argument.

So, Douglas's comment is that saving the entire workspace can be
unsafe no matter how much cleaning up you do.  I *think* a safe
alternate to save.image() is to use a save() command to save specific,
***R/SEXP-only*** objects that are the results of your computation.

I realize this doesn't entirely answer your question about rebuilding
your C++ objects between sessions, e.g. between quit(save='no').  But,
if you can do all of your computations is one session, you should be
able to save the (R/SEXP only) results to an .RData file ala:
save(list.of.results.with.no.reference.to.modules, file='BATCH-results.RData)

hope that clarifies things a bit,

A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!

More information about the Rcpp-devel mailing list