Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I improve the Makevars file for a Rcpp (RcppEigen) package?

Tags:

r

makefile

rcpp

I have a R package for which I moved an MCMC algorithm containing matrix algebra to C++ using the RcppEigen package which dramatically improved the speed.

However, R CMD check gives the following NOTE on Linux (Thanks to R-Forge):

* checking installed package size ... NOTE
  installed size is  6.6Mb
  sub-directories of 1Mb or more:
    libs   6.1Mb

This warning is probably not driven by the incredible size of my C++ code (which is only around 150 lines), as it only appears on Linux, but probably by my inability to correctly configure the Makevars file. (I have never used make or a makefile before).
Also when submitting the package to CRAN, Brian Ripley wrote something regarding this NOTE that makes me expect it is a Makevars problem: "It comes from debugging symbols."

My Makevars are the standard Rcpp Makevars (given below) produced by Rcpp.package.skeleton.

My questions:

  • How can I configure my Makevars in a way that reduces the size of the compiled library on Linux (i.e., get rid of the NOTE)?
  • What are good resources on how to get into the magic of Makevars for Rcpp?
    (I didn't find anything in the Gallery and the R extension manual on this was also incomprehensible to me)

my Makevars:

## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` 
PKG_CPPFLAGS =  -I. -I../inst/include 

my Makevars.win:

## This assume that we can call Rscript to ask Rcpp about its locations
## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = $(shell $(R_HOME)/bin/Rscript.exe -e "Rcpp:::LdFlags()")
PKG_CPPFLAGS =  -I. -I../inst/include 
like image 752
Henrik Avatar asked May 22 '13 10:05

Henrik


1 Answers

You quote what we wrote. There is nothing specific here: you just want to learn about basic Makefile syntax and options.

Fiddling with src/Makevars, unless you understand what you are doing, is not recommended. You will likely break something, particularly builds on another architecture. Simon Urbanek is pretty adamant about this advice.

Brian Ripley is of course half-correct: If you have debugging enabled, libraries are larger. But CXXFLAGS are never set, particularly no -g flag is set to turn debugging on. So it is not us: if debugging is enabled by default, something else turned it on. Could be R by default. See your .R/Makevars.

The other driver for size is C++ templates. Compare with other packages using (Rcpp)Eigen, they are likely large too. This "is just a cost of doing business": the templates give you the (coding) power you enjoy.

Edited for typos

like image 157
Dirk Eddelbuettel Avatar answered Oct 14 '22 12:10

Dirk Eddelbuettel