[Rcpp-devel] Wrapping a c++ class with singleton using RCPP Module

Dirk Eddelbuettel edd at debian.org
Wed Feb 21 13:49:17 CET 2024


On 21 February 2024 at 09:21, Iñaki Ucar wrote:
| Could you please provide more details about what you tried so far and what are
| the issues you found? A link to a public repo with a test case would be even
| better.

Seconded!

I think I also did something like that 'way early' and 'way simply'. In just
one file you can just have.

   class Foo { ... };   // forward declaration, or actual declaration

   static Foo* myfooptr = nullptr;

followed by a few simple Rcpp function to init (ie allocated), set a value,
get a value and maybe destroy at end (even callable via on.exit() from R).

The key really is to differentiate between types Rcpp knows, and those types
or classes you have that it doesn't -- so you have to write accessors in
terms of the types R knows. We must have examples for that somewhere...

Cheers, Dirk

-- 
dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list