[Rcpp-devel] How to put the code 2013-01-05-r-function-from-c++.cpp in the src/ directory of a package?

Dirk Eddelbuettel edd at debian.org
Fri May 24 13:18:56 CEST 2013


On 24 May 2013 at 05:17, Peng Yu wrote:
| I want to put the C++ function "callFunction" in a cpp file in src/
| directory of an R package and use R (in R/) to call such a function.
| Because I want to avoid the compilation need each time to use the
| function. Could anybody show me an example how to do so? Thanks.

Read the R documentation manual "Writing R Extensions" to learn the basics
about packages and they are created.

Read the vignette "Rcpp-package" to learn about creating a package with Rcpp
(hint: use Rcpp.package.skeleton).

Stick callFunction() in that package.

(Note though that just because you call an R function from C++ does NOT
accelerate that R function. It is still an R function, and as fast or slow as
before. But yes, you can call it from C++.)

Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list