Of course. Here's what comes from the S4 unit tests in the Rcpp package.
First, create a class trackin R. Then we create a minimal function that creates the object S4, providing a string to the constructor and returning 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 the values ββof the slots, etc. pp from C ++.
source
share