Compilation error using STAN from RStudio

Hello,

I would like to use the function ulam() developed by Robert McElreth in its book “Statistical Rethinking”, and therefore installed rstan on my computer, following the instructions on mc-stan.org.
The installation went fine, so I ran
pkgbuild::has_build_tools(debug = TRUE)
which returned “TRUE”, as expected.

I then configured the C++ toolchain, following the instructions, with:
dotR <- file.path(Sys.getenv(“HOME”), “.R”)
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, ifelse(.Platform$OS.type == “windows”, “Makevars.win”, “Makevars”))
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native",
if( grepl("^darwin", R.version$os)) “CXX14FLAGS += -arch x86_64 -ftemplate-depth-256” else
if (.Platform$OS.type == “windows”) “CXX11FLAGS=-O3 -march=native -mtune=native” else
“CXX14FLAGS += -fPIC”,
file = M, sep = “\n”, append = TRUE)
and all went well.

However, when I tried to fit a very simple model, I got an error message, that I pasted here below.
The data and model are:

load and rep data

library(rethinking)
data(rugged)
d <- rugged
d$log_gdp <- log(d$rgdppc_2000)
dd <- d[ complete.cases(d$rgdppc_2000) , ]
dd.trim <- dd[ , c(“log_gdp”,“rugged”,“cont_africa”) ]

new model with uniform prior on sigma

m8.1_unif <- ulam(
alist(
log_gdp ~ dnorm(mu,sigma),
mu <- a + bRrugged + bAcont_africa + bARruggedcont_africa,
a ~ dnorm(0,100),
bR ~ dnorm(0,10),
bA ~ dnorm(0,10),
bAR ~ dnorm(0,10),
sigma ~ dunif(0,10)
),
data=dd.trim , chains=2 )

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Error in .shlib_internal(commandArgs(TRUE)) :
C++14 standard requested but CXX14 is not defined
Calls: -> .shlib_internal
Exécution arrêtée
De plus : Warning message:
In system(cmd, intern = !verbose) :
l’exécution de la commande ‘C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB file1bd42f7b47b4.cpp 2> file1bd42f7b47b4.cpp.err.txt’ renvoie un statut 1
Error in sink(type = “output”) : connexion incorrecte

I don’t understand what the problem is. I tried uninstalling and reinstalling rstan but it didn’t help.

I use Windows 7pro, 64bit, and it is the last version of rstan that I installed. I have the last version of R too (3.6). The problem is the same in RStudio and in the basic interface of R.

When I run writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”)))
I get an error message saying
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:/Users/David/Documents/.R/Makevars’: No such file or directory

However, if I replace “.R/Makevars” by “.R/Makevars.win” in the command line above, then I get the following:
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native

As the devtools::session_info(“rstan”) line, it returns the following:

  • Session info -----------------------------------------------------------------------------------------------------------------------------
    setting value
    version R version 3.6.0 (2019-04-26)
    os Windows 7 x64 SP 1
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate French_France.1252
    ctype French_France.1252
    tz Europe/London
    date 2019-05-21

  • Packages ---------------------------------------------------------------------------------------------------------------------------------
    ! package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)
    backports 1.1.4 2019-04-10 [1] CRAN (R 3.6.0)
    BH 1.69.0-1 2019-01-07 [1] CRAN (R 3.6.0)
    callr 3.2.0 2019-03-15 [1] CRAN (R 3.6.0)
    checkmate 1.9.3 2019-05-03 [1] CRAN (R 3.6.0)
    cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)
    desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0)
    digest 0.6.19 2019-05-20 [1] CRAN (R 3.6.0)
    fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0)
    ggplot2 * 3.1.1 2019-04-07 [1] CRAN (R 3.6.0)
    glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.0)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0)
    inline 0.3.15 2018-05-18 [1] CRAN (R 3.6.0)
    labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)
    lattice 0.20-38 [3]
    lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0)
    loo 2.1.0 2019-03-13 [1] CRAN (R 3.6.0)
    magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)
    MASS 7.3-51.4 [3]
    Matrix 1.2-17 2019-03-22 [1] CRAN (R 3.6.0)
    matrixStats 0.54.0 2018-07-23 [1] CRAN (R 3.6.0)
    R mgcv [?]
    munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0)
    nlme 3.1-140 2019-05-12 [1] CRAN (R 3.6.0)
    pillar 1.4.0 2019-05-11 [1] CRAN (R 3.6.0)
    pkgbuild 1.0.3 2019-03-20 [1] CRAN (R 3.6.0)
    pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.6.0)
    plyr 1.8.4 2016-06-08 [1] CRAN (R 3.6.0)
    prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0)
    processx 3.3.1 2019-05-08 [1] CRAN (R 3.6.0)
    ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0)
    R6 2.4.0 2019-02-14 [1] CRAN (R 3.6.0)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0)
    Rcpp 1.0.1 2019-03-17 [1] CRAN (R 3.6.0)
    RcppEigen 0.3.3.5.0 2018-11-24 [1] CRAN (R 3.6.0)
    reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.6.0)
    rlang 0.3.4 2019-04-07 [1] CRAN (R 3.6.0)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)
    rstan * 2.18.2 2018-11-07 [1] CRAN (R 3.6.0)
    scales 1.0.0 2018-08-09 [1] CRAN (R 3.6.0)
    StanHeaders * 2.18.1 2019-01-28 [1] CRAN (R 3.6.0)
    stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)
    stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)
    tibble 2.1.1 2019-03-16 [1] CRAN (R 3.6.0)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0)
    vctrs 0.1.0 2018-11-29 [1] CRAN (R 3.6.0)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.0)
    withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)
    zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.6.0)

[1] C:/Users/David/Documents/R_Libraries
[2] C:/Users/David/Documents/R/win-library/3.6
[3] C:/Program Files/R/R-3.6.0/library

R – Package was removed from disk.

Could the problem be that I use a personal library (I created an environment variable to my Documents/R_Libraries).
When I run .libPaths(), it returns:
[1] “C:/Users/David/Documents/R_Libraries” “C:/Users/David/Documents/R/win-library/3.6” “C:/Program Files/R/R-3.6.0/library”

All this is way over my head, so I really hope that someone will be able to help here. In advance many thanks!

David

Copy the file .R/Makevars.win to .R/Makevars perhaps? Sorry, don’t have Windows here…

I believe this has been solved here: https://github.com/stan-dev/rstan/issues/633#issuecomment-491558135

1 Like

Oh thank you so much! It just works, after two days loosing hairs on the problem!
Thanks again!
:-)

1 Like

Thank you torkar. The problem was solved by following the link increasechief passed here, below.