[Rcpp-devel] Rcpp and ExternalPtr

Jeroen Ooms jeroen.ooms at stat.ucla.edu
Fri Dec 5 08:45:34 CET 2014


Does Rcpp provide some elegant way to let the R user manage persistent
c++ objects that have no R type (e.g. internal handles or sessions of
some sort)?

In C, I would use R_MakeExternalPtr to create a ptr SEXP that the user
can pass from one R function to another. This also makes it easy to
add a finalizer with R_RegisterCFinalizerEx so that the garbage
collector will automatically clean up the session/handle whenever user
deletes the R object.

Most Rcpp examples I have seen use function arguments with standard
data types that are automatically mapped to R types. Does Rcpp have
any special mechanics for managing external objects (pointers) from R
which do not map to a SEXP type? Or do I have to fall back on
Rinternals for this?


More information about the Rcpp-devel mailing list