Rstantools: Compilation error under Mac OSX


Operating System: OSX 10.13.2
Interface Version: RStudio 1.1.383
Compiler/Toolkit: rstantools 1.4.0

Dear all, I am trying to write a package containing a Stan program I have written (see I used the rstantools to build a package skeleton using rstantools::rstan_package_skeleton(). Everythink worked nicely so far. However, when I checked the packge using either R CMD check in the Terminal or devtools::check(), I get following error:

installing source package ‘disturbanceBayes’ ...
** libs
rm: stan_files/: is a directory
make: *** [shlib-clean] Error 1
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"../inst/include" -I""/Library/Frameworks/R.framework/Resources/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=ignore_error -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/StanHeaders/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rstan/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include" -I/usr/local/include -fPIC -Wall -g -O2 -c init.cpp -o init.o
clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o stan_files/ init.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: can't map file, errno=22 file 'stan_files/' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [] Error 1
ERROR: compilation failed for package ‘disturbanceBayes’
removing ‘/private/var/folders/fx/hyncgzcx6l35ypn4sqm6q2m00000gn/T/RtmpDxCkiU/devtools_install_15e250520bf/disturbanceBayes’

I also checked a clean package skeleton without any stan or R code by myself (i.e., plain package created by rstantools::rstan_package_skeleton()) and got the same error. I am using the newest R Version (3.4.3) and updated all packages. I am working on a Mac with OSX 10.13.2. Xcode is also installed and up-to-date.

Any ideas what causes the error and how I can fix it?


I created a PR that fixes it on GitHub.


Great, thanks Ben! It now works! However, I had to add Rcpp:: before loadModule in zzz.R.


You should have Rcpp in Depends and import everything.


Okay, got it. Works perfectly now. Thank you a lot!