[Rcpp-devel] Creating an R interface to non-copyable C++ class
cris.l.luengo at gmail.com
Thu Apr 12 01:19:55 CEST 2018
I have some functionality in C++ that I need to access from R. My
impression was that Rcpp was the simplest way to accomplish this, but I
haven't been able to make it work yet.
The core problem, I think, is that data created is not copyable. One of
these functions returns a `std::unique_ptr` owning the pointer to the
object. Other functions take a reference to the object and modify it or
Here is what I've tried so far: https://stackoverflow.com/q/49785379/7328782
Ideally, an R variable would hold on to this pointer (with or without the
`std::unique_ptr` around it), and delete the object when it is cleared (or
garbage collected, or whatever R uses). Is this possible?
The Rcpp-extending vignette says "The macro RCPP_EXPORT_WRAP provides an
easy way to expose a C++ class to R as an external pointer", but looking at
the code it seems to allocate a new object, using `new` and the copy
constructor, and wrap that. Would it be possible to modify the code
generated by this macro to not `new`, but directly use a given pointer?
Would that still allow for lifetime management?
Many thanks for your advice!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Rcpp-devel