3

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?

evolvedmicrobe
  • 2,672
  • 2
  • 22
  • 30

1 Answers1

5

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thank you! I noticed Hadley's `devtools::use_rcpp()` adds Rcpp to both `Imports` and `LinkingTo`, but doesn't add the `importFrom` line to the Namespace file, so a user should still do that manually? – evolvedmicrobe Jun 21 '18 at 23:13
  • You could just look at our documentation instead of asking me about usage patterns with a 3rd party tool I do not use myself... – Dirk Eddelbuettel Jun 21 '18 at 23:15
  • Just use `Rcpp.package.skeleton()` and see what it does. That works. The RStudio package generator for Rcpp is also good. – Dirk Eddelbuettel Jun 21 '18 at 23:17
  • Thank you again. Indeed, the RStudio package generator does add `importFrom(Rcpp, evalCpp)` to the NAMESPACE as specified by your documentation. Agreed it was unfair to ask about `devtools:use_rcpp()`. Thanks again. – evolvedmicrobe Jun 21 '18 at 23:40
  • Not unfair in the sense that `devtools` is very popular. But I have been using R for so long that my workflows never needed it so `` from here -- I just cannot answer usage question. All you asked _is_ both documented _and_ done right by these generators and helper -- just not by the one you picked. Unlucky you. – Dirk Eddelbuettel Jun 21 '18 at 23:50