Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting existing C++ code to R

Tags:

c++

r

rcpp

poker

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:

  1. Will I need to make any changes to the C++ source to make it compatible with Rcpp?
  2. 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.

like image 509
Zach Avatar asked Dec 01 '11 21:12

Zach


1 Answers

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.

like image 70
Dirk Eddelbuettel Avatar answered Oct 20 '22 14:10

Dirk Eddelbuettel