Installing rstan on a remote server

Hi,
I’m trying to install rstan on a remote server (a Unix computing cluster) and I can’t get the package to install correctly. I’m relatively new to using a remote server like this, but the same procedure is working for other R packages.

Outside of R (in the terminal on the remote machine), I’m creating a file:
cat > install-packages.R
dir.create(Sys.getenv(“R_LIBS_USER”), showWarnings = FALSE, recursive = TRUE) install.packages(c(“StanHeaders”, “rstan”, “Rcpp”, “RcppEigen”, “inline”, “BH”), repos = “http://cloud.r-project.org/”, dependencies=TRUE)

I run this file with: R CMD BATCH install-packages.R

Then when I’m in R, and I tried to load libraries rstan and StanHeaders, I get the error message that these packages do not exist. But for other packages the load just fine.

I’ve also tried placing the rstan_2.16.2.tar.gz file in my library, but I’ve had the same problem.

Has anybody had success installing on a remote server, and what did you do?
Thank you,
Mikey

My guess is these R packages are being installed to the wrong directory. Maybe try

stopifnot(nchar(Sys.getenv("R_LIBS_USER")) > 0)
dir.create(Sys.getenv("R_LIBS_USER"), showWarnings = FALSE, recursive = TRUE)
install.packages("rstan", repos = "http://cloud.r-project.org", 
                 lib = Sys.getenv("R_LIBS_USER"))

Hi Ben,
Thank you for your quick response. I tried running this, and I was unsuccessful. I’ve pasted the log file below.
Thank you,
Mikey

stopifnot(nchar(Sys.getenv(“R_LIBS_USER”)) > 0)
dir.create(Sys.getenv(“R_LIBS_USER”), showWarnings = FALSE, recursive = TRUE)
install.packages(“rstan”, repos = “http://cloud.r-project.org”,

  •              lib = Sys.getenv("R_LIBS_USER"))
    

also installing the dependencies ‘StanHeaders’, ‘RcppEigen’

trying URL ‘http://cloud.r-project.org/src/contrib/StanHeaders_2.16.0-1.tar.gz
Content type ‘application/x-gzip’ length 942256 bytes (920 KB)

downloaded 920 KB

trying URL ‘http://cloud.r-project.org/src/contrib/RcppEigen_0.3.3.3.0.tar.gz
Content type ‘application/x-gzip’ length 1634023 bytes (1.6 MB)

downloaded 1.6 MB

trying URL ‘http://cloud.r-project.org/src/contrib/rstan_2.16.2.tar.gz
Content type ‘application/x-gzip’ length 733666 bytes (716 KB)

downloaded 716 KB

  • installing source package ‘StanHeaders’ …
    ** package ‘StanHeaders’ successfully unpacked and MD5 sums checked
    ** libs
    clang -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -DNO_FPRINTF_OUTPUT -Icvodes/include/ -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -fpic -m64 -mavx -xHost -mkl -c cvodes/src/cvodes/cvodes.c -o cvodes/src/cvodes/cvodes.o
    make: clang: Command not found
    make: *** [cvodes/src/cvodes/cvodes.o] Error 127
    ERROR: compilation failed for package ‘StanHeaders’
  • removing ‘/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders’
  • installing source package ‘RcppEigen’ …
    ** package ‘RcppEigen’ successfully unpacked and MD5 sums checked
    ** libs
    clang++ -arch x86_64 -ftemplate-depth-256 -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -I"/pfs/bh/apps/user/intel-16/R-3.3.1/lib64/R/library/Rcpp/include" -I…/inst/include -fpic -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -flto -ffat-lto-objects -Wno-unused-local-typedefs -Wno-ignored-attributes -Wno-deprecated-declarations -c RcppEigen.cpp -o RcppEigen.o
    /bin/sh: clang++: command not found
    make: *** [RcppEigen.o] Error 127
    ERROR: compilation failed for package ‘RcppEigen’
  • removing ‘/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen’
    ERROR: dependency ‘StanHeaders’ is not available for package ‘rstan’
  • removing ‘/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/rstan’

The downloaded source packages are in
‘/tmp/RtmpupffoV/downloaded_packages’
Warning messages:
1: In install.packages(“rstan”, repos = “http://cloud.r-project.org”, :
installation of package ‘StanHeaders’ had non-zero exit status
2: In install.packages(“rstan”, repos = “http://cloud.r-project.org”, :
installation of package ‘RcppEigen’ had non-zero exit status
3: In install.packages(“rstan”, repos = “http://cloud.r-project.org”, :
installation of package ‘rstan’ had non-zero exit status

proc.time()
user system elapsed
3.688 0.479 5.910

The server needs to have clang++ installed.

Thank you Ben. I’m working on convincing the server administrators to install it.

A recent version of g++ would work as well.

I managed to get the compilers installed. Now I’m getting different error messages depending on how I try to load rstan. Below is one example. I appreciate any help y’all can provide.
Thank you,
Mikey

Installing package into ‘/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'http://cran.cnr.berkeley.edu/src/contrib/rstan_2.16.2.tar.gz
Content type ‘application/x-gzip’ length 733666 bytes (716 KB)

downloaded 716 KB

  • installing source package ‘rstan’ …
    ** package ‘rstan’ successfully unpacked and MD5 sums checked
    ** libs
    icpc -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I""/apps/user/intel-16/R-3.3.1/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/BH/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include" -fpic -m64 -mavx -xHost -mkl -c chains.cpp -o chains.o
    icpc -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I""/apps/user/intel-16/R-3.3.1/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/BH/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include" -fpic -m64 -mavx -xHost -mkl -c init.cpp -o init.o
    icpc -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I""/apps/user/intel-16/R-3.3.1/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/BH/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include" -fpic -m64 -mavx -xHost -mkl -c lang__ast_def.cpp -o lang__ast_def.o
    In file included from /pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast.hpp(68),
    from /pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast_def.cpp(7),
    from lang__ast_def.cpp(18):
    /pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast/node/conditional_op.hpp(40): error: data member initializer is not allowed
    bool has_var_ = false;
    ^

compilation aborted for lang__ast_def.cpp (code 2)
make: *** [lang__ast_def.o] Error 2
ERROR: compilation failed for package ‘rstan’

  • removing ‘/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/rstan’

The downloaded source packages are in
‘/tmp/Rtmp31Pi4Y/downloaded_packages’
Warning message:
In install.packages(“rstan”) :
installation of package ‘rstan’ had non-zero exit status

Yeah, I messed that up and apparently icpc won’t tolerate that. You can try installing after first doing

export USE_CXX11=1

in the bash shell.

Hi Ben,
Thanks again for your response. I ran this in the bash shell and got what I think is the same error (pasted below). I appreciate any other ideas that you might have.
Thank you,
Mikey

Installing package into ‘/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'http://cran.cnr.berkeley.edu/src/contrib/rstan_2.16.2.tar.gz
Content type ‘application/x-gzip’ length 733666 bytes (716 KB)

downloaded 716 KB

  • installing source package ‘rstan’ …
    ** package ‘rstan’ successfully unpacked and MD5 sums checked
    ** libs
    icpc -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I""/apps/user/intel-16/R-3.3.1/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/BH/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include" -fpic -m64 -mavx -xHost -mkl -c chains.cpp -o chains.o
    icpc -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I""/apps/user/intel-16/R-3.3.1/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/BH/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include" -fpic -m64 -mavx -xHost -mkl -c init.cpp -o init.o
    icpc -I/apps/user/intel-16/R-3.3.1/lib64/R/include -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I""/apps/user/intel-16/R-3.3.1/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -DFUSION_MAX_VECTOR_SIZE=12 -I/apps/user/intel-16/intel-16.3/compilers_and_libraries/linux/mkl/include -I/apps/user/intel-16/libxml2-2.9.4/include -I/apps/user/intel-16/zlib-1.2.8/include -I/apps/user/intel-16/libcurl-7.50.0/include -I/apps/user/intel-16/bzip2-1.0.6/include -I/apps/user/intel-16/xz-5.2.2/include -I/apps/user/intel-16/pcre-8.39/include -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/Rcpp/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/RcppEigen/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/BH/include" -I"/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include" -fpic -m64 -mavx -xHost -mkl -c lang__ast_def.cpp -o lang__ast_def.o
    In file included from /pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast.hpp(68),
    from /pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast_def.cpp(7),
    from lang__ast_def.cpp(18):
    /pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast/node/conditional_op.hpp(40): error: data member initializer is not allowed
    bool has_var_ = false;
    ^

compilation aborted for lang__ast_def.cpp (code 2)
make: *** [lang__ast_def.o] Error 2
ERROR: compilation failed for package ‘rstan’

  • removing ‘/pfs/bh/home/mtabak/R/x86_64-pc-linux-gnu-library/3.3/rstan’

The downloaded source packages are in
‘/tmp/RtmpbvihOQ/downloaded_packages’
Warning message:
In install.packages(“rstan”) :
installation of package ‘rstan’ had non-zero exit status

Thank you for all of your help, Ben. I had someone help me with this and we found that the problem was in the header file. The intel c compiler threw an error because of assigning a value to has_var_ in the header file. We fixed that as follows and then it compiles.

diff R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast/node/conditional_op.hpp R/x86_64-pc-linux-gnu-library/3.3/StanHeaders/include/src/stan/lang/ast/node/conditional_op.hpp~

40c40
<       bool has_var_ ;
---
>       bool has_var_ = false;

Good. This is already fixed in the next version of Stan.