There is an S4 R class whose object I need to create in Rcpp. Is it possible to do this, and if yes, how?
Sure. Here is something taken from the S4 unit tests in the Rcpp package.
We first create a track
class in R. We then create a minimal function creating an S4
object by supplying a string to the constructor and return it:
R> setClass("track", representation(x="numeric", y="numeric"))
R> cppFunction('SEXP trythis(std::string txt) { S4 foo(txt); return foo; }')
R> trythis("track")
An object of class "track"
Slot "x":
numeric(0)
Slot "y":
numeric(0)
R>
You can set slot values etc pp from C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With