compileCode error when I run the models in a sever with Ubuntu

rstan

#1

Hi,
I’m trying to install rstan in a server with Ubuntu and I get the following error, when I run any model.

 schools_dat <- list(J = 8,
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
 fit <-  stan(file = '8schools.stan', data = schools_dat)

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! During startup - Warning messages:
1: Setting LC_TIME failed, using β€œC”
2: Setting LC_MONETARY failed, using β€œC”
3: Setting LC_PAPER failed, using β€œC”
4: Setting LC_MEASUREMENT failed, using β€œC”
In file included from /usr/include/c++/5/thread:35:0,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/mat/functor/map_rect_concurrent.hpp:10,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/mat/functor/map_rect.hpp:13,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/mat.hpp:262,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /usr/local/lib/R/site-library/StanHeaders/include/stan/math.hpp:4,
from /usr/local/lib/R/site-library/StanHeaders/include/src/stan/model/model_header.hpp:4,
from file9b550aef0d1.cpp:8:
/
In addition: Warning message:
running command β€˜/usr/lib/R/bin/R CMD SHLIB file9b550aef0d1.cpp 2> file9b550aef0d1.cpp.err.txt’ had status 1
Error in sink(type = β€œoutput”) : invalid connection


The IT guy first install the binary version for Ubuntu with r-cran-rstan. But it didn’t work, and then he followed the instructions of https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux. And the installation was successful. But I can’t get the models to run. I’ve checked that Rcpp works fine in R. (I just ran a few examples I found).

Details about the server and installation:

  • Operating System: Ubuntu 16.04.5 LTS
  • RStan Version: 2.18.2
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14=clang++-3.8
CXXFLAGS+=-flto -Wno-unused-local-typedefs
CXXFLAGS += -DSTAN_THREADS
CXXFLAGS += -pthread

but I also tried with g++
I checked and
g++ -version says 5.4.0
but there is g++, g+Β±4.9 and g+Β±5 installed, as well as
clang+Β±3.8 and clang+Β±3.6. Can that be a problem?

  • Output of devtools::session_info("rstan")
─ Session info ───────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 os       Ubuntu 16.04.5 LTS          
 system   x86_64, linux-gnu           
 ui       X11                         
 language en_US:en                    
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Berlin               
 date     2018-12-04                  

─ Packages ───────────────────────────────────────────────────────────────────
 package      * version   date       lib source        
 assertthat     0.2.0     2017-04-11 [1] CRAN (R 3.4.4)
 backports      1.1.2     2017-12-13 [1] CRAN (R 3.4.4)
 base64enc      0.1-3     2015-07-28 [1] CRAN (R 3.4.4)
 BH             1.66.0-1  2018-02-13 [1] CRAN (R 3.4.4)
 callr          3.0.0     2018-08-24 [1] CRAN (R 3.4.4)
 cli            1.0.1     2018-09-25 [1] CRAN (R 3.4.4)
 colorspace     1.3-2     2016-12-14 [1] CRAN (R 3.4.4)
 crayon         1.3.4     2017-09-16 [1] CRAN (R 3.4.4)
 desc           1.2.0     2018-05-01 [1] CRAN (R 3.4.4)
 digest         0.6.18    2018-10-10 [1] CRAN (R 3.4.4)
 fansi          0.4.0     2018-10-05 [1] CRAN (R 3.4.4)
 ggplot2      * 3.1.0     2018-10-25 [1] CRAN (R 3.4.4)
 glue           1.3.0     2018-07-17 [1] CRAN (R 3.4.4)
 gridExtra      2.3       2017-09-09 [2] CRAN (R 3.4.4)
 gtable         0.2.0     2016-02-26 [1] CRAN (R 3.4.4)
 inline         0.3.15    2018-05-18 [2] CRAN (R 3.4.4)
 labeling       0.3       2014-08-23 [2] CRAN (R 3.2.3)
 lattice        0.20-38   2018-11-04 [4] CRAN (R 3.4.4)
 lazyeval       0.2.1     2017-10-29 [1] CRAN (R 3.4.4)
 loo            2.0.0     2018-04-11 [1] CRAN (R 3.4.4)
 magrittr       1.5       2014-11-22 [2] CRAN (R 3.2.3)
 MASS           7.3-51.1  2018-11-01 [4] CRAN (R 3.4.4)
 Matrix         1.2-15    2018-11-01 [4] CRAN (R 3.4.4)
 matrixStats    0.54.0    2018-07-23 [1] CRAN (R 3.4.4)
 mgcv           1.8-26    2018-11-21 [4] CRAN (R 3.4.4)
 munsell        0.5.0     2018-06-12 [1] CRAN (R 3.4.4)
 nlme           3.1-137   2018-04-07 [4] CRAN (R 3.4.4)
 pillar         1.3.0     2018-07-14 [1] CRAN (R 3.4.4)
 pkgbuild       1.0.2     2018-10-16 [1] CRAN (R 3.4.4)
 plyr           1.8.4     2016-06-08 [1] CRAN (R 3.4.4)
 prettyunits    1.0.2     2015-07-13 [1] CRAN (R 3.4.4)
 processx       3.2.0     2018-08-16 [1] CRAN (R 3.4.4)
 ps             1.2.1     2018-11-06 [1] CRAN (R 3.4.4)
 R6             2.3.0     2018-10-04 [1] CRAN (R 3.4.4)
 RColorBrewer   1.1-2     2014-12-07 [2] CRAN (R 3.2.3)
 Rcpp           1.0.0     2018-11-07 [1] CRAN (R 3.4.4)
 RcppEigen      0.3.3.4.0 2018-02-07 [1] CRAN (R 3.4.4)
 reshape2       1.4.3     2017-12-11 [1] CRAN (R 3.4.4)
 rlang          0.3.0.1   2018-10-25 [1] CRAN (R 3.4.4)
 rprojroot      1.3-2     2018-01-03 [1] CRAN (R 3.4.4)
 rstan        * 2.18.2    2018-11-07 [3] CRAN (R 3.4.4)
 scales         1.0.0     2018-08-09 [1] CRAN (R 3.4.4)
 StanHeaders  * 2.18.0    2018-10-07 [1] CRAN (R 3.4.4)
 stringi        1.2.4     2018-07-20 [1] CRAN (R 3.4.4)
 stringr        1.3.1     2018-05-10 [1] CRAN (R 3.4.4)
 tibble         1.4.2     2018-01-22 [1] CRAN (R 3.4.4)
 utf8           1.1.4     2018-05-24 [1] CRAN (R 3.4.4)
 viridisLite    0.3.0     2018-02-01 [1] CRAN (R 3.4.4)
 withr          2.1.2     2018-03-15 [1] CRAN (R 3.4.4)

[1] /home/nicenboim/R/x86_64-pc-linux-gnu-library/3.4
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

#2

Try it again with passing verbose = TRUE to stan() to see a bit more of the error messages.


#3

It’s quite long, here it is
output.txt (80.7 KB)


#4

Always look for the first occurrence of the string error: (with colon), which in this case is

/home/nicenboim/R/x86_64-pc-linux-gnu-library/3.4/StanHeaders/include/stan/math/rev/core/var.hpp:473:18: error: use of undeclared identifier β€˜nullptr’
if (v.vi_ == nullptr)

which means it didn’t use the right C++ standard. You might need a

CXX14STD = -std=c++14

in your ~/.R/Makevars file.


#5

it worked!!!
Thank you!!!