[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
Mon May 27 01:00:18 CEST 2013

On 26 May 2013 at 17:39, Peng Yu wrote:
| The straight forward answer to my question in the title is that
| 2013-01-05-r-function-from-c++.cpp should not be directly put to src/
| direction in an R package. 

Sorry but that is once again incorrect. Read the "Rcpp attributes" vignette,
and learn about compileAttributes().  It does the wrapping of the posted
function for you, and it does it right.  It provides the passage from a
single function (or several functions) you can test via sourceCpp() to a

Of course, one could also manually rewrite it for use in a package (and do
what we did before Rcpp attributes). I would even call that easy (as your
function is simple). But your attempts at that were rather wrong, though, as
you mixed pieces from different approaches seemingly at random.

All this is really fairly basic.  Take a day off, then read the docs, start
from an even simpler example and work your way up from there.  Passing an R
function from R to a C++ routine that is called from R is not difficult, but
you have been managing to get lost for a few days now.


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

More information about the Rcpp-devel mailing list