通过 RInside 的“R”;实例作为类/方法之间的参数
我一直在使用Rcpp和RInside来集成R和C++。我们有一个复杂但设计良好的 C++ 架构,我发现很难仅从 1 个函数中访问 R。是否可以将 R 实例传递给不同的类/函数,以获得更多的 OOP 设计?如果有,有什么例子吗?
为了详细说明查询, 我想说的是,
void foo(RInside& R0, int& x0)
{
R0.assign(x0,"totalSum");
}
void foo2(RInside& R0, int& y0)
{
R0.assign(y0,"temp");
R0.parseEvalQ("totalSum = totalSum + temp");
}
int main(int argc, char *argv[])
{
RInside R(int argc, char *argv[]);
int x=10, y = 11;
foo(R,x);
foo2(R,y);
return 0;
}
我目前注意到的是,每次调用 foo 可能都会创建一个新的 RInside 实例。
谢谢你-埃贡
I have been using Rcpp and RInside, to integrate R and C++. We have a complex, yet well designed C++ architecture, and I am finding it difficult to access R from within just 1 function. Is it possible to pass the R
instance to different Classes / functions, to get a more OOP design ? If yes, are there any examples ?
To elaborate the query,
I want to say that something like this,
void foo(RInside& R0, int& x0)
{
R0.assign(x0,"totalSum");
}
void foo2(RInside& R0, int& y0)
{
R0.assign(y0,"temp");
R0.parseEvalQ("totalSum = totalSum + temp");
}
int main(int argc, char *argv[])
{
RInside R(int argc, char *argv[]);
int x=10, y = 11;
foo(R,x);
foo2(R,y);
return 0;
}
What I am currently noticing is that each call to foo, probably creates a new instance of RInside.
Thank you - Egon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,正如我之前写的rcpp-devel 列表(如果你关心 Rcpp 和 RInside,你应该关注它)我刚刚向 RInside 将其嵌入 Qt。
我在
main()
中实例化 R,然后将此对象的引用传递给使用它的类。这似乎是一个合适的模型,因为我们需要确保只有一个 R 实例正在运行(R 不是多线程等)——如果您需要更多实例,请考虑 Rserve。此示例为 现在在 SVN 中,在我的盒子上看起来像这样:
我非常喜欢它,因为它可以让您尝试混合、分散两个绘图的中心位置等,并查看您没有的带宽更长地区分估计密度的两个驼峰。
Yes, and as I wrote earlier to the rcpp-devel list (which you should follow if you care about Rcpp and RInside) I just added an example to RInside which embeds it inside Qt.
I instantiante R in
main()
and then pass a reference to this object to the class using it. That seems like a proper model as we need to make sure that only one R instance is running (with R not being multithreaded etc---if you need more instances, consider Rserve.This example is now in SVN and looks like this on my box:
I quite like it as it lets you play around with mixtures, spread the central location of both draws etc and see at which bandwidth you no longer differentiate between two humps of the estimated density.