<div dir="ltr"><div>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.<br><br>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 query it.<br><br>Here is what I've tried so far: <a href="https://stackoverflow.com/q/49785379/7328782">https://stackoverflow.com/q/49785379/7328782</a><br><br>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?<br><br>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?<br><br>Many thanks for your advice!<br></div>Cris.<br><br></div>