Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling R functions from VC++

Tags:

c++

r

visual-c++

I need to run statistical functions from R within my C++ code. Is there a way to call them from my C++ code? I'm using VS 2005, do I need to include any header files or link any libraries? I installed R using the standard Windows installer provided from their website.

Regards,

like image 980
Jawad Avatar asked Oct 23 '22 14:10

Jawad


1 Answers

Briefly:

  • As has been stated fairly frequently, R itself does not build under VS* making the linking of C code hard-but-possible and C++ code impossible (as function header information is not standardized).

  • Both Rcpp and RInside work perfectly well on Windows, given the standard Windows toolchain. (RInside did have a bug but this is now fixed.)

    The Rcpp FAQ has more to say about VS* (ie that you cannot expect this to work if R itself can't work with the compiler)

  • If you must use VS* then your best bet may be looser coupling via networking and using Rserve.

    If you can switch compilers then Rcpp / RInside can be of interest; and the rest of the R API is also at your disposal.

  • Rcpp et al have copious documentation, including an Rcpp-introduction pdf (which is also peer-reviewed article) and the aforementioned Rcpp-FAQ --- as well as a dedicated mailing list.

And please do not cross-post. I also just answered this on r-help.

like image 198
Dirk Eddelbuettel Avatar answered Oct 27 '22 10:10

Dirk Eddelbuettel