rrcpprcpp11

Do I need to specify Rcpp in both Imports and LinkingTo in order to avoid a Makevars file?


According to the Rcpp FAQ (2.15. What about the new ‘no-linking’ feature), since Rcpp version 0.11.0 we can avoid specifying LAPACK/BLAS/Fortran in a Makevars file, and in fact avoid a Makevars entirely if we follow these instructions.

... only two things are required: • an entry in DESCRIPTION such as Imports: Rcpp (which may be versioned as in Imports: Rcpp (>= 0.11.0)), and • an entry in NAMESPACE to ensure Rcpp is correctly instantiated, for example importFrom(Rcpp, evalCpp).

But instead of adding an Imports line for Rcpp, would a LinkingTo also work? That is, can I use:

LinkingTo: Rcpp (>= 0.11.0)

instead of:

Imports: Rcpp (>= 0.11.0)

Or are both needed?


Solution

  • In short, no -- you need both just as we say as they have different purposes.

    LinkingTo: is, for all intents and purposes, a directive for R to tell the compiler where needed header files are. Packages building against Rcpp must have this.

    Imports: deals with the package namespace and initialization on package load / attach. Rcpp is "almost" purely header-based but a little bit of code needs to be executed.

    All this is documented for R in the Writing R Extensions manual and for Rcpp in our package vignettes.