Cannot open Stan example models

Hi everyone,

New Stan and R user here. I wanted to play with the example Eight Schools model to get a feel for Stan so I ran the following code:

library(rstan)

stan_demo("eight_schools")

After which, I received the following error message:

> J <- 8

> y <- c(28,  8, -3,  7, -1,  1, 18, 12)

> sigma <- c(15, 10, 16, 11,  9, 11, 10, 18)

> tau <- 25
Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  '-E' not found
2: In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file21e873413f17.cpp 2> file21e873413f17.cpp.err.txt' had status 1
3: In file(con, "r") :
  cannot open file 'file21e873413f17.cpp.err.txt': No such file or directory
Error in sink(type = "output") : invalid connection

I have absolutely no idea what this means. Any help would be much appreciated!

Here is my system/environment information:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Also- using rstan version 2.21.2

Hi

could this perhaps be connected to the issues people have reported with Windows + rstan? Please check the forum and if you can’t find anything get back here. :)

1 Like

I’ll have time tonight to take a look and get back to you with what I find

If you don’t find a fix, can you run:

example(stan_model,run.dontrun = TRUE,verbose=TRUE)

and post the line that starts with error:?

1 Like

@andrjohns @torkar So I went through the thread on rstan and windows, and followed the advice on my Makevars.win file. Rstan works, but only in certain situations.

If I call the rstan library as in

library(rstan)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)

and try to run the Eight Schools model, I get the error code

Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/RBUILD~1/4.0/usr/mingw_/bin/g++' not found
2: In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/bin/x64/R CMD SHLIB file559c50ec76a2.cpp 2> file559c50ec76a2.cpp.err.txt' had status 1
3: In file(con, "r") :
  cannot open file 'file559c50ec76a2.cpp.err.txt': No such file or directory
Error in sink(type = "output") : invalid connection

But when I don’t call at the beginning and instead use

fit <- rstan::stan(model_code = model, data = schools_dat)

the model runs with the following warning messages

Warning messages:
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/RBUILD~1/4.0/usr/mingw_/bin/g++' not found
2: There were 1 divergent transitions after warmup. See
http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them. 
3: Examine the pairs() plot to diagnose sampling problems

Hopefully this is helpful, and if you need me to check/try anything else just let me know. I’m just glad I can get models up and running :)

@andrjohns @torkar I tried uninstalling and re-installing rstan, and am now getting a different error message when I follow along with the Eight Schools model on the Getting Started page. When I try and fit the model, I get

Error in withr::set_makevars(new, path, state, assignment = assignment) : 
  Multiple results for CXX14FLAGS found, something is wrong.FALSE
In addition: Warning message:
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/RBUILD~1/4.0/usr/mingw_/bin/g++' not found

I’ve checked my Makevars.win, which looks like this

CXX14FLAGS=-O3 -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7



CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2

Any ideas as to what is causing these errors?

The error is: Multiple results for CXX14FLAGS

And you have multiple CXX14FLAGS set in your MAKEFLAGS file. Try removing the first CXX14FLAGS and the CXX11FLAGS and running again

3 Likes