# Cannot open Stan example models

**URL:** <https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168>\
**Category:** Interfaces\
**Created:** [August 2, 2020, 12:30am UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168 "2020-08-02T00:30:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![graham](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@graham](https://discourse.mc-stan.org/u/graham)\
**Post date:** [August 2, 2020, 12:30am UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/1 "2020-08-02T00:30:47Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![graham](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@graham](https://discourse.mc-stan.org/u/graham)\
**Post date:** [August 2, 2020, 12:40am UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/2 "2020-08-02T00:40:57Z")

</div>

Also- using rstan version 2.21.2

---

<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:** [August 5, 2020, 5:48pm UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/3 "2020-08-05T17:48:36Z")

</div>

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. :)

---

<div class="post-metadata">

**Author:** ![graham](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@graham](https://discourse.mc-stan.org/u/graham)\
**Post date:** [August 6, 2020, 3:36pm UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/4 "2020-08-06T15:36:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [August 6, 2020, 3:38pm UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/5 "2020-08-06T15:38:48Z")

</div>

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:`?

---

<div class="post-metadata">

**Author:** ![graham](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@graham](https://discourse.mc-stan.org/u/graham)\
**Post date:** [August 7, 2020, 12:58am UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/6 "2020-08-07T00:58:52Z")

</div>

@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 :)

---

<div class="post-metadata">

**Author:** ![graham](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@graham](https://discourse.mc-stan.org/u/graham)\
**Post date:** [August 9, 2020, 12:56am UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/7 "2020-08-09T00:56:18Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [August 9, 2020, 1:57am UTC](https://discourse.mc-stan.org/t/cannot-open-stan-example-models/17168/8 "2020-08-09T01:57:12Z")

</div>

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
