Compiling R

When I am compiling a model in Rstan from Rstudio it pops up with
“Building R package from source requires installation of additional build tools. Do you want to install additional tools now.”
It works even if I say No. However it will output the following to the console:

Trying to compile a simple C file
Running /usr/local/lib/R/bin/R CMD SHLIB foo.c
using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
gcc -I"/usr/local/lib/R/include" -DNDEBUG   -I"/usr/local/lib/R/site-library/Rcpp/include/"  -I"/usr/local/lib/R/site-library/RcppEigen/include/"  -I"/usr/local/lib/R/site-library/RcppEigen/include/unsupported"  -I"/usr/local/lib/R/site-library/BH/include" -I"/usr/local/lib/R/site-library/StanHeaders/include/src/"  -I"/usr/local/lib/R/site-library/StanHeaders/include/"  -I"/usr/local/lib/R/site-library/RcppParallel/include/"  -I"/usr/local/lib/R/site-library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -D_HAS_AUTO_PTR_ETC=0  -include '/usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include    -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c foo.c -o foo.o
In file included from /usr/local/lib/R/site-library/RcppEigen/include/Eigen/Core:88,
                 from /usr/local/lib/R/site-library/RcppEigen/include/Eigen/Dense:1,
                 from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22,
                 from <command-line>:
/usr/local/lib/R/site-library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name ‘namespace’
  628 | namespace Eigen {
      | ^~~~~~~~~
/usr/local/lib/R/site-library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  628 | namespace Eigen {
      |                 ^
In file included from /usr/local/lib/R/site-library/RcppEigen/include/Eigen/Dense:1,
                 from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22,
                 from <command-line>:
/usr/local/lib/R/site-library/RcppEigen/include/Eigen/Core:96:10: fatal error: complex: No such file or directory
   96 | #include <complex>
      |          ^~~~~~~~~
compilation terminated.
make: *** [/usr/local/lib/R/etc/Makeconf:191: foo.o] Error 1'

It happens for all models, even the 8-schools model.

Again, it actually works. But it is annoying that we have to say Yes or No to this popup. We are using Rstan in a system where this message may come after hours of running; stopping the process until the user logs on and engages with the dialog box.
I am sure the first suggestion is to reinstall. However this is a clean installation. In fact, we are running Rstudio from a Docker, so every restart gets a clean installation.
The issue goes away for awhile when restarting the Rstudio session. Also, we never have problems when running outside Rstudio.

If your question relates to installation please provide the following information:

  • Operating System. Docker running Ubuntu Linux
  • RStan Version: R version 4.3.0 (2023-04-21)
  • Rstudio: 2023.06.2 Build 561
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function

CXXFLAGS += -flto -ffat-lto-objects -Wno-unused-local-typedefs

CXXFLAGS += -Wno-ignored-attributes -Wno-deprecated-declarations -Wno-deprecated
  • Output of devtools::session_info("rstan"): rstan * 2.32.3 2023-10-15 [1] CRAN (R 4.3.0)

I am not sure this is a bug in Rstan. I am, however, looking for tips as to what I can check or change. Do anyone know e.g. why it is “Trying to compile a simple C file”?

If you’re having trouble with RStan, you might want to try CmdStanR. It’s not on CRAN, but it’s more up to date with Stan than RStan, which is still struggling with restrictive CRAN policies on dependencies and package size.