Distributing TMB functions in R package and CRAN checks

662 Views Asked by At

I have 9 cpp files in /src - 8 from Rcpp and 1 from TMB. I can compile all and run code successfully OR get passed the CRAN checks. But not both.

Method 1

Let R compile all cpp files and generate a single DLL: 'mypackage.dll' and TMB::MakeADfun(..., DLL="mypackage"):

  • passes all CRAN checks (except note on installed package size, see below).
  • Rcpp functions work fine
  • call to TMB function results in: Error in .Call("getParameterOrder", data, parameters, new.env(), PACKAGE = DLL) : "getParameterOrder" not available for .Call() for package "mypackage"
  • using TMB::MakeADFun(..., DLL="mypackage", checkParameterOrder=FALSE) results in: Error in .Call("TMBconfig", e, as.integer(1), PACKAGE = DLL) : "TMBconfig" not available for .Call() for package "mypackage"

Method 2

Use 'makevars.win' following this suggestion, add useDynLib MyTMB, and TMB::MakeADfun(..., DLL="MyTMB") and create two DLLs (mypackage.dll and MyTMB.dll):

makevars.win:

all: MyTMB.dll

MyTMB.dll: MyTMB.cpp
    $(R_HOME)/bin$(R_ARCH_BIN)/Rscript --vanilla -e "TMB::compile('MyTMB.cpp', safebounds=FALSE, safeunload=FALSE)"

clean:
  rm -rf *o
  • both Rcpp and TMB functions work
  • devtools::check() results in one warning for each of the Rcpp functions:

    checking foreign function calls ... WARNING
        Foreign function calls to a different package:
          .Call("_rcppfunction1", ..., PACKAGE = "mypackage")
    
  • and one note on large installed package size. The libs sub-directory is over 30 Mb and about twice the size of Method 1.

Rcpp developers recommend not to use a makevars file, and obviously I'm overwriting something from Rcpp to cause the 'foreign function calls' issue, even though the package is the current package. It seems my options are:

  • modify 'makevars' to restore the Rcpp defaults that avoid the warning, and plead with CRAN to accept the note on installed package size. Not sure how to do the former.
  • find fix to Method 1 problem, and plead with a smaller installed package size. Would be the simplest solution with only one dll. Not sure if the problem is caused because I'm compiling both Rcpp and TMB, and if so, how to fix it.
  • or something else that I'm missing.

Any suggestions?

R details:

platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 3.3

0

There are 0 best solutions below