Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to import RccpEigen in the DESCRIPTION file for an R package using it, or is "LinkingTo" enough?

Tags:

c++

r

rcpp

eigen

I used the RcppEigen.package.skeleton() as a template for adding a small function to an existing R package, so that my DESCRIPTION file now has the lines:

Imports: Rcpp (>= 0.11.3), RcppEigen (>= 0.3.2.3.0)
LinkingTo: Rcpp, RcppEigen

However, doing R CMD check --as-cran <myPackageName_1.0.0>.tar.gz gives the following:

"Package in Depends/Imports which should probably only be in LinkingTo: 'RcppEigen'"

The Writing R Extensions page says: "Specifying a package in ‘LinkingTo’ suffices if these are C++ headers containing source code or static linking is done at installation: the packages do not need to be (and usually should not be) listed in the ‘Depends’ or ‘Imports’ fields. This includes CRAN packages BH and almost all users of RcppArmadillo and RcppEigen."

I don't know any C++, so I don't know what this means. My procedure for creating the package is here: RcppEigen - going from inline to a .cpp function in a package and "Map"

Is it okay to remove the RcppEigen from "Imports" and why/why not? (i.e. Can you please explain what the Writing R Extension page is saying, for my case, so that I can understand what I'm doing? Both the R and software experts in my lab said they don't understand the difference between "Imports" and "LinkingTo".)

like image 478
Catalina Avatar asked Nov 16 '25 09:11

Catalina


1 Answers

Briefly:

  1. There are currently 25 packages on CRAN which use RcppEigen. That makes 25 working case studies. You could look at one or two.
  2. LinkingTo: is generally enough.
  3. It may be a bug that the skeleton generator still adds Imports. We no longer do that in RcppArmadillo.

When I just ran the corresponding function for RcppArmadillo, I got

Imports: Rcpp (>= 0.11.3)
LinkingTo: Rcpp, RcppArmadillo

so I am leaning towards a bug. And I now opened an issue ticket for it.

More broadly, the differences between LinkingTo: and Imports: are

  • Imports: is the preferred, modern alternative to Depends; you also need to use NAMESPACE
  • LinkingTo: is chiefly used to point to header files as we do here.

So Writing R Extensions, or Hadley's online book for details.

like image 197
Dirk Eddelbuettel Avatar answered Nov 18 '25 01:11

Dirk Eddelbuettel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!