当然.这是从Rcpp包中的S4单元测试中获取的东西.
我们首先track在R中创建一个类.然后我们S4通过向构造函数提供一个字符串并返回它来创建一个创建对象的最小函数:
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>
Run Code Online (Sandbox Code Playgroud)
您可以从C++设置插槽值等pp.