[Rcpp-devel] Rcpp and ExternalPtr

Jeroen Ooms jeroen.ooms at stat.ucla.edu
Sun Dec 7 06:41:53 CET 2014


On Fri, Dec 5, 2014 at 12:54 AM, Romain François
<romain at r-enthusiasts.com> wrote:
>
> You are looking for XPtr.

Thanks guys, exactly what I needed indeed. One follow-up question:

Is there a way to use the XPtr object to prevent the c++ object it
points to from going out of scope? It seems like the c++ garbage
collector destroys the handle after the function returns, even though
the handle is referenced by the XPtr that I just created. I was hoping
that it would automatically be protected as long as the EXTPTRSXP is
pointing to it, but that does not seem to be the case.

I am currently working around it by maintaining a list of handles in
the global scope, but it would be more elegant if R(cpp) would take
care of it.


More information about the Rcpp-devel mailing list