8

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 
Henrik
  • 14,202
  • 10
  • 68
  • 91

1 Answers1

7

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

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 1
    Thanks for the response, just to clarify: What your are saying is basically (a) there really is no problem, the size comes from the structure of `Eigen`, (b) there are no recommended `CXXFLAGS` flags to set for `RcppEigen`, and (c) if you want to change the flags go and learn _basic Makefile syntax and options_. Am I understanding you correctly? – Henrik May 22 '13 at 10:56
  • Yes to a) and c); we do say what you need in b) and give to you; look at the RcppEigen docs, examples and skeleton package -- but in essence you just need LinkingTo: RcppEigen. You do use RcppEigen, and not separate copy of Eigen, right? – Dirk Eddelbuettel May 22 '13 at 11:35
  • Yes, I use `RcppEigen` and I probably have actually used `RcppEigen.package.skeleton` (as I have `RcppEigen` before `Rcpp` on both Depends and LinkingTo in the `DESCRIPTION`). My question is perhaps if it makes sense to set e.g. the famous `-O3` option (and if so, how)? – Henrik May 22 '13 at 11:44
  • Now we're talking -- search on StackOverflow or also on eg http://rseek.org for `.R/Makevars` or just `Makevars`. You typically set those _globally_ for R, rather than per package. – Dirk Eddelbuettel May 22 '13 at 12:17
  • @DirkEddelbuettel Hi I am trying to use Rcpp in my C++ project and use it in R. the project uses C++11 and what is your recomended way to use C++11 in Rcpp? Now I add the flag `-std=c++11` in Makevars file. But you said it is not the recommended way. So what is your suggestions? – Luyi Tian Mar 27 '17 at 05:35