[Rcpp-devel] Linking to c++ files in a package without Rcpp overhead for faster computation

Dirk Eddelbuettel edd at debian.org
Fri Mar 6 23:30:49 CET 2015


On 6 March 2015 at 17:09, JJ Allaire wrote:
| The overhead comes from the fact that the parameters are converted
| to/from SEXP and pushed through a C interface. There's also overhead
| that's associated with error checking, etc. This is a fixed overhead
| so as more work gets done inside your C++ function the % overhead will
| approach zero.
| 
| In terms of re-using code across packages, everything in your
| inst/include directory is automatically added to the include search
| path of any package that has a LinkingTo relationship to yours (and to
| any sourceCpp module that does an Rcpp::depends on it). No absolute
| paths are therefore necessary (R resolves the path to your package at
| build time).
| 
| If you want to re-use Rcpp code across packages the most
| straightforward way to do it is inside a header file (this has no
| linking or associated C interface overhead, and has no versioning
| problems). You can just define your function with the 'inline' keyword
| and it can be re-used in an arbitrary number of other C++ files with
| no linker conflicts.

"What JJ said."

Coincidentally, the same questin came up at StackOverflow yesterday, with a
wrong initial Subject: asking for header-onlu and only later revealing that
full linking was required.  In bits and pieces I answerd something very
similar to what JJ says here:

http://stackoverflow.com/questions/28883314/rcpp-include-header-from-package-into-cppfunction

Dirk 

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


More information about the Rcpp-devel mailing list