Conflict with Rcpp

I have a problem installing packages such as party after installing rstan. I have reinstalled R from scratch at now it did fine. I have a suspicion that modifications to .R/Makevars required by rstan causes the packages that are installed later to use include files that have namespace in them (i.e. complex.h in RcppEigen) and thus gcc breaks. I don’t know what is the root cause so would appreciate any advice.

I would not rule it out, but I don’t think so. RStan is one of the few packages to enforce the use of the C++14 standard. Rcpp and non-Stan packages that use Rcpp tend to use C++11 (or C++98), in which case their behavior is governed by CXX11FLAGS (or CXXFLAGS) in ~/.R/Makevars.

If you have more details about the problem, we could probably figure it out.

Well, probably it will take some time until the same happens again. But I will try reconstructing from memory. After installing and configuring rstan (it ran fine) I decided to install party package (because it figures out variable importance using random forests - I would prefer to use some Bayesian instead but didn’t find so far). During installation I saw errors that were given by RcppEigen something folder complex.h file alluding that it doesn’t understand namespace. I figured out it shouldn’t since it was gcc. After I added to .R/Makevars CC=g++ compilation went fine (since g++ was invoked) but the .so library was not properly created (symbol party.init was not found). Thus I decided to reinstall from scratch. Currently my system (Ubuntu 18.04) doesn’t have rstan installed. When I looked at Rcpp package as it currently is I saw that indeed there is complex.h file but it doesn’t contain namespace as well there is nothing resembling RcppEigen. For some reason I think that rstan installs RcppEigen and it somehow creates a mess. Possibly it could be eliminated by .R/Makevars. Any suggestions?

I am not familiar with the party package, but I will try to install it and take a look.

Thanks. And, if possible, can you please send the .R/Makevars?

I think I stumbled upon the same problem. I installed rstan according to Configuring C Toolchain for Linux · stan-dev/rstan Wiki · GitHub, including setting the makevars:

# cat  ~/.R/Makevars
CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=g++

Afterwards, the installation of evd fails:

> renv::install('evd')
Retrieving 'https://cran.rstudio.com/src/contrib/evd_2.3-6.1.tar.gz' ...
        OK [file is up to date]
Installing evd [2.3-6.1] ...
        FAILED
Error installing package 'evd':
===============================

* installing *source* package ‘evd’ ...
** package ‘evd’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
gcc -I"/usr/share/R/include" -DNDEBUG   -I"/project/renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/Rcpp/1.0.9/e9c08b94391e9f3f97355841229124f2/Rcpp/include/"  -I"/project/renv/library/R-4.2/x86_64-pc-linux-gnu/RcppEigen/include/"  -I"/project/renv/library/R-4.2/x86_64-pc-linux-gnu/RcppEigen/include/unsupported"  -I"/project/renv/library/R-4.2/x86_64-pc-linux-gnu/BH/include" -I"/project/renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/StanHeaders/2.21.0-7/0459d4dd7a8c239be18469a30c23dd4b/StanHeaders/include/src/"  -I"/project/renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/StanHeaders/2.21.0-7/0459d4dd7a8c239be18469a30c23dd4b/StanHeaders/include/"  -I"/project/renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/RcppParallel/5.1.5/f3e94e34ff656a7c8336ce01207bc2b8/RcppParallel/include/"  -I"/project/renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/rstan/2.21.7/62745645aadeb276b67ddb9f0993cfeb/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/project/renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/StanHeaders/2.21.0-7/0459d4dd7a8c239be18469a30c23dd4b/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1      -fpic  -g -O2 -ffile-prefix-map=/build/r-base-J8F88F/r-base-4.2.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c bvpot.c -o bvpot.o
In file included from /project/renv/library/R-4.2/x86_64-pc-linux-gnu/RcppEigen/include/Eigen/Core:88,
                 from /project/renv/library/R-4.2/x86_64-pc-linux-gnu/RcppEigen/include/Eigen/Dense:1,
                 from /project/renv/cache/v5/R-4.2/x86_64-pc-linux-gnu/StanHeaders/2.21.0-7/0459d4dd7a8c239be18469a30c23dd4b/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13,
                 from <command-line>:
/project/renv/library/R-4.2/x86_64-pc-linux-gnu/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name ‘namespace’
  628 | namespace Eigen {
      | ^~~~~~~~~
/project/renv/library/R-4.2/x86_64-pc-linux-gnu/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  628 | namespace Eigen {
      |                 ^
/project/renv/library/R-4.2/x86_64-pc-linux-gnu/RcppEigen/include/Eigen/Core:96:10: fatal error: complex: No such file or directory
   96 | #include <complex>
      |          ^~~~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:168: bvpot.o] Error 1
ERROR: compilation failed for package ‘evd’
* removing ‘/project/renv/staging/1/evd’
Error: install of package 'evd' failed [error code 1]
Traceback (most recent calls last):
11: renv::install("evd")
10: renv_install_impl(records)
 9: renv_install_staged(records)
 8: renv_install_default(records)
 7: handler(package, renv_install_package(record))
 6: renv_install_package(record)
 5: withCallingHandlers(renv_install_package_impl(record), error = function(e) {
        vwritef("\tFAILED")
        writef(e$output)
    })
 4: renv_install_package_impl(record)
 3: r_cmd_install(package, path)
 2: r_exec_error(package, output, "install", status)
 1: stop(error)

you may notice that the compilation steps for that package brings in Stan-related files.

Would you be able to help?

I think you just need to restart R, making sure that no packages get loaded (and don’t load rstan/StanHeaders), and then try again.

2 Likes

Excellent, that works. Easy