简体   繁体   English

RInside InternalFunction在类上,如何从R调用函数

[英]RInside InternalFunction on a class, how to call the function from R

I need to call R from C++ and I am using the excellent RInside / Rccp packages. 我需要从C ++调用R,并且正在使用出色的RInside / Rccp软件包。 I am not an R specialist, this might explain my question and sorry if it's too obvious. 我不是R专家,这可能会解释我的问题,如果太明显,则很抱歉。

I made an object and a wrapper class, something similar to the Rinside examples/standard/rinside_interactive0.cpp. 我创建了一个对象和一个包装器类,类似于Rinside示例/standard/rinside_interactive0.cpp。 In this example it shows how to attach a method to an R attribute class. 在此示例中,它显示了如何将方法附加到R属性类。

wr.attr("class") = "Solver";    
R["Solver"] = wr;
... more code
R["names.Solver"] = Rcpp::InternalFunction(& Names); <-- Hot to call this one from R

Actually I never see a call from R to this function, and what would be the R syntax ? 实际上,我从未见过R调用此函数,R语法是什么? I though, using R.parseEval in such way: 我虽然以这种方式使用R.parseEval:

R.parseEval("Solver.names()");

But this does not work and gives the error: 但这不起作用,并给出错误:

Error in Solver.names() : could not find function "Solver.names"
terminate called after throwing an instance of 'std::runtime_error'
what():  Error evaluating: Solver.names()

My question is then how to call the Solver.names function in R (that is handled in the C++ code) ? 然后我的问题是如何在R中调用Solver.names函数(在C ++代码中处理)? Note that the assign / retrieval function are working fine, maybe because they are somehow "primitive" ? 请注意,分配/检索功能运行良好,可能是因为它们在某种程度上是“原始”的?

Thanks a lot Franck 非常感谢Franck

I found out, I post in case someone is searching: 我发现了,如果有人在搜索,我会发布:

R.parseEval("names.Solver(Solver)");

Not very elegant to me .., it uses functionName.class(Object) .. 对我来说不是很优雅..它使用functionName.class(Object)..

F. F。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM