kaskr / adcomp

AD computation with Template Model Builder (TMB)
Other
175 stars 80 forks source link

TMB fails to compile when using `renv` #323

Closed DanOvando closed 4 years ago

DanOvando commented 4 years ago

Description:

compilation of TMB models fails when run inside of an renv environment

Reproducible Steps:

I'm migrating my projects to be build around renv for dependency management. This however is creating some problems for TMB.

To reproduce

  1. In a clean environment, install TMB, and then run
library(TMB)

TMB::runExample("simple", clean = TRUE)

Works just fine.

  1. install renv

  2. run renv::init()

  3. run renv::install("TMB")

  4. run

library(TMB)

TMB::runExample("simple", clean = TRUE)

and I get the following error

Cleanup:
Building example simple 
Note: Using Makevars in /Users/danovan/.R/Makevars 
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/Users/danovan/Library/Application Support/renv/cache/v5/R-4.0/x86_64-apple-darwin17.0/TMB/1.7.18/1500330bbd3c378400d65a5010aa7ce5/TMB/include -I/Users/danovan/packages/ex/renv/library/R-4.0/x86_64-apple-darwin17.0/RcppEigen/include  -DTMB_SAFEBOUNDS -DLIB_UNLOAD=R_unload_simple  -DTMB_LIB_INIT=R_init_simple   -I/usr/local/include   -fPIC  -Wall -g -O2  -c simple.cpp -o simple.o
clang: error: no such file or directory: 'Support/renv/cache/v5/R-4.0/x86_64-apple-darwin17.0/TMB/1.7.18/1500330bbd3c378400d65a5010aa7ce5/TMB/include'
make: *** [simple.o] Error 1
Error in compile(paste0(name, ".cpp"), ...) : Compilation failed
In addition: Warning messages:
1: In file.remove(dynlib(name)) :
  cannot remove file 'simple.so', reason 'No such file or directory'
2: In file.remove(paste0(name, ".o")) :
  cannot remove file 'simple.o', reason 'No such file or directory'
Timing stopped at: 0.033 0.017 0.056

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] TMB_1.7.18

loaded via a namespace (and not attached):
[1] compiler_4.0.2  Matrix_1.2-18   tools_4.0.2     grid_4.0.2      renv_0.11.0-23  lattice_0.20-41

I submitted an issue first over at renv, and they suggested the following

"Based on this output, the issue here is that the path to the TMP include directory is not being quoted.

I'd recommend filing a bug for the package author, indicating that the paths created here:

https://github.com/kaskr/adcomp/blob/ea5238611af919a67e60ba129a83a7abf1768d58/TMB/R/TMB.R#L1083-L1091

need to be quoted, to ensure spaces (and other special characters) are properly handled."

I'd try and mess with it myself but will admit that in this context I'm not entirely clear what "needs to be quoted" means

TMB Version:

1.7.18

R Version:

4.0.2

Operating System:

macOS 10.15.6

bbolker commented 4 years ago

This seems to have gotten onto the mailing list but not here (where it is probably more useful

I would rewrite this as follows (or something like this) [untested!]

sf <- function(x,package="TMB",cond=TRUE) {
     sprintf('-I"%s"',system.file(x,package=package)[cond])
}

ppflags <- paste(sf("include"),
                 sf("include",package="RcppEigen",cond=useRcppEigen),
                 sf("include/contrib",cond=useContrib),
                   "-DTMB_SAFEBOUNDS"[safebounds],
                   paste0("-DLIB_UNLOAD=R_unload_",libname)[safeunload],
                   "-DWITH_LIBTMB"[libtmb],
                   paste0("-DTMB_LIB_INIT=R_init_",libname)[libinit],
                   "-DCPPAD_FORWARD0SWEEP_TRACE"[tracesweep]
                   ) 
kaskr commented 4 years ago

@DanOvando

Does this solve it?:

devtools::install_github("kaskr/adcomp/TMB", ref="quote_path")

And does it work on Windows? (shortPathName mixed with quotes...)

Edit: My first try had issues with precompile. Second try added to same branch.

DanOvando commented 4 years ago

That does it, thanks! I can confirm that TMB::runExample now works on both my mac and windows builds when renv is activated.

kaskr commented 4 years ago

Merged