# Compilation error using STAN from RStudio

**URL:** <https://discourse.mc-stan.org/t/compilation-error-using-stan-from-rstudio/8899>\
**Category:** RStan\
**Tags:** rstan\
**Created:** [May 21, 2019, 2:25pm UTC](https://discourse.mc-stan.org/t/compilation-error-using-stan-from-rstudio/8899 "2019-05-21T14:25:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidB](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DavidB](https://discourse.mc-stan.org/u/DavidB)\
**Post date:** [May 21, 2019, 2:25pm UTC](https://discourse.mc-stan.org/t/compilation-error-using-stan-from-rstudio/8899/1 "2019-05-21T14:25:58Z")

</div>

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](http://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 + bR_rugged + bA_cont\_africa + bAR_rugged_cont\_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

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [May 21, 2019, 2:55pm UTC](https://discourse.mc-stan.org/t/compilation-error-using-stan-from-rstudio/8899/2 "2019-05-21T14:55:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![increasechief](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/increasechief/32/2039_2.png) [@increasechief](https://discourse.mc-stan.org/u/increasechief)\
**Post date:** [May 21, 2019, 3:22pm UTC](https://discourse.mc-stan.org/t/compilation-error-using-stan-from-rstudio/8899/3 "2019-05-21T15:22:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DavidB](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DavidB](https://discourse.mc-stan.org/u/DavidB)\
**Post date:** [May 21, 2019, 3:47pm UTC](https://discourse.mc-stan.org/t/compilation-error-using-stan-from-rstudio/8899/4 "2019-05-21T15:47:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DavidB](https://avatars.discourse-cdn.com/v4/letter/d/76d3ee/32.png) [@DavidB](https://discourse.mc-stan.org/u/DavidB)\
**Post date:** [May 21, 2019, 3:48pm UTC](https://discourse.mc-stan.org/t/compilation-error-using-stan-from-rstudio/8899/5 "2019-05-21T15:48:37Z")

</div>

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