移植现有的 C++代码到R
我想将 SpecialK Poker Hand evaluator 移植到 R。我认为使用 Rcpp 包 应该相对容易,但是我不知道从哪里开始。
现有教程似乎专注于开发在 R 中使用的新 C++ 代码。在本例中,I有 C++ 可以解决问题,并且我想在 R 中以最小的麻烦使用此代码。如果代码是一个独立的函数,我可以使用 内联,但这在这里不起作用。
我想这个问题有两个部分:
- 我需要对 C++ 源代码进行任何更改以使其与 Rcpp 兼容吗?
- 鉴于它不小,我如何从 R 调用这段代码, 我可以使用动态编译和链接的独立函数 排队?
我也愿意使用 Java、Python 或 Objective-C 版本的评估器,但我认为这些版本不会更容易链接到 R。
I would like to port the SpecialK Poker Hand evaluator to R. I think this should be relatively easy using the Rcpp package, but I have no idea where to begin.
The existing tutorials seem to focus on developing new C++ code for use in R. In this case, I have C++ that solves a problem, and I want to use this code in R with minimum hassle. If the code were one, self-contained function, I could compile and link it on the fly with inline, but this doesn't work here.
I guess this question has 2 parts:
- Will I need to make any changes to the C++ source to make it compatible with Rcpp?
- How do I call this code from R, given that it's not a small,
self-contained function I can compile and link dynamically using
inline?
I am also open to using the Java, python, or objective-C versions of the evaluator, but I don't think those will be easier to link to R.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否看过 Rcpp ,它使得将 R 和 C++ 结合起来相当轻松?
许多软件包使用它将现有的 C++ 代码引入 R。您还可以在此处查看
[rcpp]
标签下的问题。软件包中、我的网站和其他地方都有相当广泛的文档。Have you looked at Rcpp which makes it fairly painfree to combine R and C++?
Lots of packages use it to bring existing C++ code to R. You can also look at questions here under the
[rcpp]
tag. Fairly extensive documentation in the package, at my site and other places.