[Rcpp-devel] Making objects in the C++ "side" persistent

Martin Jakt mjakt at z2.keio.jp
Fri Jun 13 08:21:07 CEST 2014

Hi Dirk,

> | I'm wondering how you've gotten on with this. I'm struggling with a
> | somewhat similar problem in my own package. This uses the 'Rcpp modules'
> | to provide an interface to a couple of C++ functions. This works very
> | well, but accessing the objects (created by new()) after a save/reload
> | cycle results in R crashing.
> It is a known shortcoming.

that's what I understood, but it's good to have it confirmed.

> I think this is the right route.  And we now have access to serialize() from
> the C/C++ side (via the small package RApiSerialize which I used in
> RcppRedis). It should not be too hard to move towards something like
> saveRDS/readRDS. Maybe you can experiment with explicitly deserialization
> of the 'payload' of your object, and then recreate it?

I'll have to have a look at that, and see how I can use it.

> There were some old discussions when Modules was new and fresh, but nobody
> has worked out a solution.  It should be doable, though, or at least
> "approximatively".  But we can rely on just 'save' or 'saveImage'.  We need
> to do the extra step.

I have a feeling that I've read at least part of that discussion, but I was 
unable to find the thread again. In particular I have a feeling that the use of 
.Last() was discussed. 

I played around a bit with interposing save() and defining a .Last() function 
(for details, see my previous email to Fernando), and this works, but has 
potential to conflict with other packages and hence cannot provide any 
guaranteed behaviour.

> | I'd also like to say that I _really_ appreciate Rcpp, especially the
> | sourceCpp function; it's makes R comfortable to use. Thanks to the
> | developers.
> Thanks for the kind words. Many of us use it too :)

I'm afraid that resorting to sourceCpp is often easier than trying to find out 
how to do something efficiently in R. Not sure if that's good for my R skills, 
but at least I can get my work done. And I do get a feeling that there are 
things that really can't be done fast in R, so being able to easily drop down 
into C++ makes it easy to do what otherwise would be either difficult or very 



Martin Jakt
Department of Systems Medicine
Mitsunada Sakaguchi Laboratory
Keio University School of Medicine

More information about the Rcpp-devel mailing list