# Unable to install rstan\_2.19.2 from CRAN

**URL:** <https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643>\
**Category:** Interfaces\
**Tags:** rstan\
**Created:** [July 10, 2019, 11:50am UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643 "2019-07-10T11:50:10Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dale\_Steele](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dale_steele/32/1221_2.png) [@Dale\_Steele](https://discourse.mc-stan.org/u/Dale_Steele)\
**Post date:** [July 10, 2019, 11:50am UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/1 "2019-07-10T11:50:10Z")

</div>

I attempted to install rstan 2.19.2 on 64 bit Windows 10 from CRAN - the install fails (details below). I don’t see a 2.19.2 version of StanHeaders on CRAN - is this the cause?

install.packages(“rstan”, repos = “[https://cloud.r-project.org/](https://cloud.r-project.org/)”, dependencies = TRUE)

There is a binary version available but the source version is later:  
binary source needs\_compilation  
rstan 2.18.2 2.19.2 TRUE

The install fails as below:

> … In file included from C:/Program Files/R/R-3.6.1/library/StanHeaders/include/src/stan/lang/generator/generate\_function\_instantiation.hpp:6:0,  
> from C:/Program Files/R/R-3.6.1/library/StanHeaders/include/src/stan/lang/generator/generate\_function\_instantiations.hpp:5,  
> from C:/Program Files/R/R-3.6.1/library/StanHeaders/include/src/stan/lang/generator/generate\_standalone\_functions.hpp:7,  
> from C:/Program Files/R/R-3.6.1/library/StanHeaders/include/src/stan/lang/compile\_functions.hpp:4,  
> from stanc.cpp:23:  
> C:/Program Files/R/R-3.6.1/library/StanHeaders/include/src/stan/lang/generator/generate\_function\_instantiation\_body.hpp: In function ‘void stan::lang::generate\_function\_instantiation\_body(const stan::lang::function\_decl\_def&, const std::vector\<std::basic\_string \>&, bool, bool, bool, const string&, std::ostream&)’:  
> C:/Program Files/R/R-3.6.1/library/StanHeaders/include/src/stan/lang/generator/generate\_function\_instantiation\_body.hpp:44:45: error: range-based ‘for’ loops are not allowed in C++98 mode  
> for (const std::string& namespace\_i : namespaces) {  
> ^  
> make: \*\*\* [C:/PROGRA~1/R/R-3.6.1/etc/x64/Makeconf:215: stanc.o] Error 1  
> ERROR: compilation failed for package ‘rstan’
> 
> - removing ‘C:/Program Files/R/R-3.6.1/library/rstan’  
> Warning in install.packages :  
> installation of package ‘rstan’ had non-zero exit status

Operating System: Windows 10  
Interface Version: rstan  
Compiler/Toolkit: Rtools version 3.5.0.4

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [July 10, 2019, 2:56pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/2 "2019-07-10T14:56:02Z")

</div>

I would install the binary version via

```
install.packages("https://win-builder.r-project.org/rTkumr03G8UM/rstan_2.19.1.zip", repos = NULL)

```

to install from source, you would have to get the configuration right

> **[stan-dev/rstan](https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows#configuration)**
>
> RStan, the R interface to Stan. Contribute to stan-dev/rstan development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Dale\_Steele](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dale_steele/32/1221_2.png) [@Dale\_Steele](https://discourse.mc-stan.org/u/Dale_Steele)\
**Post date:** [July 10, 2019, 3:58pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/3 "2019-07-10T15:58:31Z")

</div>

What version of StanHeaders is required? The version on CRAN is 2.18.1-10.

The ‘Depends’ for rstan 2.19.1 is given as ‘Depends: R (\>= 3.4.0), StanHeaders (\> 2.18.1)’

I’m able to load rstan, but running the blocker example generates a new error:

> fit ← stan(file = ‘blocker.stan’, data = blocker\_dat)  
> Error in new\_CppObject\_xp(fields$.module, fields$.pointer, …) :  
> Exception: variable does not exist; processing stage=data initialization; variable name=N; base type=int (in ‘model404c329a55fe\_blocker’ at line 4)

failed to create the sampler; sampling not done

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [July 10, 2019, 4:24pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/4 "2019-07-10T16:24:30Z")

</div>

That StanHeaders is fine. What is `names(blocker_dat)`?

---

<div class="post-metadata">

**Author:** ![Dale\_Steele](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dale_steele/32/1221_2.png) [@Dale\_Steele](https://discourse.mc-stan.org/u/Dale_Steele)\
**Post date:** [July 10, 2019, 4:28pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/5 "2019-07-10T16:28:10Z")

</div>

library(rstan)  
rstan\_options(auto\_write = TRUE)  
options(mc.cores = parallel::detectCores())

“rt” \<-  
c(3, 7, 5, 102, 28, 4, 98, 60, 25, 138, 64, 45, 9, 57, 25, 33,  
28, 8, 6, 32, 27, 22)  
“nt” \<-  
c(38, 114, 69, 1533, 355, 59, 945, 632, 278, 1916, 873, 263,  
291, 858, 154, 207, 251, 151, 174, 209, 391, 680)  
“rc” \<-  
c(3, 14, 11, 127, 27, 6, 152, 48, 37, 188, 52, 47, 16, 45, 31,  
38, 12, 6, 3, 40, 43, 39)  
“nc” \<-

c(39, 116, 93, 1520, 365, 52, 939, 471, 282, 1921, 583, 266,  
293, 883, 147, 213, 122, 154, 134, 218, 364, 674)  
“N” \<-  
22

blocker\_dat \<- list(“rt”, “nt”, “rc”, “nc”, “N”)  
fit \<- stan(file = ‘blocker.stan’, data = blocker\_dat)  
print(fit)

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [July 10, 2019, 4:35pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/6 "2019-07-10T16:35:38Z")

</div>

> [@Dale\_Steele](#):
>
> blocker\_dat ← list(“rt”, “nt”, “rc”, “nc”, “N”)

Specifying the data by character vector appears to have gotten broken when we fixed the thing where people were using `i` as a symbol name in the data block. You can get it to work if you instead do

```no-highlight
blocker_dat <- list(rt = rt, nt = nt, rc = rc, nc = nc, N = N)

```

---

<div class="post-metadata">

**Author:** ![VoidCaller](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/voidcaller/32/5669_2.png) [@VoidCaller](https://discourse.mc-stan.org/u/VoidCaller)\
**Post date:** [July 11, 2019, 8:14am UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/7 "2019-07-11T08:14:59Z")

</div>

For me the solution was to modify Makevars.win, adding $(BINPREF) to CXX14= generated by standard rstan installation instruction. My Makevars.win looks like this:

```
CXX14=$(BINPREF)g++ -O2 -march=native -mtune=native

CXX14FLAGS=-O3 -march=native
CXX14=$(BINPREF)g++ -m$(WIN) -std=c++1y
CXX11FLAGS=-O3 -march=native

```

Without the proper compiler flags I was getting all kind of compiler errors, like you reported.

---

<div class="post-metadata">

**Author:** ![Dale\_Steele](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/dale_steele/32/1221_2.png) [@Dale\_Steele](https://discourse.mc-stan.org/u/Dale_Steele)\
**Post date:** [July 11, 2019, 11:24am UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/8 "2019-07-11T11:24:34Z")

</div>

Thank you. The rstan source on CRAN (version 2.19.2 ) compiles without error for me using your Makevars.win settings.

version R version 3.6.1 (2019-07-05)

os Windows 10 x64

system x86\_64, mingw32

ui RStudio

---

<div class="post-metadata">

**Author:** ![djvanness](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/djvanness/32/17086_2.png) [@djvanness](https://discourse.mc-stan.org/u/djvanness)\
**Post date:** [July 11, 2019, 12:28pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/9 "2019-07-11T12:28:18Z")

</div>

I use the above Makevars.win above and finally got it to make progress toward compiling – just a few warnings like:

> note: #pragma message: This header is deprecated. Use \<boost/integer/integer\_log2.hpp\> instead.  
> BOOST\_HEADER\_DEPRECATED(“\<boost/integer/integer\_log2.hpp\>”);

But I still ended up exiting with Error 1:

> C:\Users\david\AppData\Local\Temp\ccPAHol3.s: Assembler messages:  
> C:\Users\david\AppData\Local\Temp\ccPAHol3.s:22629: Error: invalid register for .seh\_savexmm  
> C:\Users\david\AppData\Local\Temp\ccPAHol3.s:22631: Error: invalid register for .seh\_savexmm  
> C:\Users\david\AppData\Local\Temp\ccPAHol3.s:22633: Error: invalid register for .seh\_savexmm  
> C:\Users\david\AppData\Local\Temp\ccPAHol3.s:22635: Error: invalid register for .seh\_savexmm  
> C:\Users\david\AppData\Local\Temp\ccPAHol3.s:22637: Error: invalid register for .seh\_savexmm  
> C:\Users\david\AppData\Local\Temp\ccPAHol3.s:25575: Error: invalid register for .seh\_savexmm  
> make: \*\*\* [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: chains.o] Error 1  
> ERROR: compilation failed for package ‘rstan’
> 
> - removing ‘C:/Users/david/Documents/R/win-library/3.6/rstan’
> - restoring previous ‘C:/Users/david/Documents/R/win-library/3.6/rstan’  
> Warning in install.packages :  
> installation of package ‘rstan’ had non-zero exit status

Here is my sessionInfo()

> R version 3.6.1 (2019-07-05)  
> Platform: x86\_64-w64-mingw32/x64 (64-bit)  
> Running under: Windows 10 x64 (build 17134)
> 
> Matrix products: default
> 
> locale:  
> [1] LC\_COLLATE=English\_United States.1252  
> [2] LC\_CTYPE=English\_United States.1252  
> [3] LC\_MONETARY=English\_United States.1252  
> [4] LC\_NUMERIC=C  
> [5] LC\_TIME=English\_United States.1252
> 
> attached base packages:  
> [1] stats graphics grDevices utils datasets methods base
> 
> loaded via a namespace (and not attached):  
> [1] compiler\_3.6.1 tools\_3.6.1 packrat\_0.5.0

---

<div class="post-metadata">

**Author:** ![jjramsey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jjramsey/32/3319_2.png) [@jjramsey](https://discourse.mc-stan.org/u/jjramsey)\
**Post date:** [July 11, 2019, 12:34pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/10 "2019-07-11T12:34:28Z")

</div>

> [@djvanness](#):
>
> Error: invalid register for .seh\_savexmm

Judging from the following link, leaving out `-march=native` from `CXX14FLAGS` and `CXX11FLAGS` may help: [Compiler Problem (rstan, Win10, 64) - #11 by avo](https://discourse.mc-stan.org/t/compiler-problem-rstan-win10-64/7787/11)

---

<div class="post-metadata">

**Author:** ![djvanness](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/djvanness/32/17086_2.png) [@djvanness](https://discourse.mc-stan.org/u/djvanness)\
**Post date:** [July 11, 2019, 12:55pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/11 "2019-07-11T12:55:52Z")

</div>

Thank you - jjramsey’s suggestion to leave off -march=native from CXX14FLAGS and CXX11FLAGS did the trick.

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [July 11, 2019, 4:59pm UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/12 "2019-07-11T16:59:07Z")

</div>

Everyone should be able to install the binaries for 2.19.2 now:

```
install.packages("rstan", repos = "https://cran.rstudio.com")

```

---

<div class="post-metadata">

**Author:** ![djvanness](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/djvanness/32/17086_2.png) [@djvanness](https://discourse.mc-stan.org/u/djvanness)\
**Post date:** [July 12, 2019, 1:42am UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/13 "2019-07-12T01:42:59Z")

</div>

Even with the new binaries 2.19.2, adding -march=native to the CXX14 and CXX11 flags throws an error when I compile 8schools.stan as a test. Perhaps it’s my processor? i7-7820X Skylake (8 cores).

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [July 12, 2019, 1:56am UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/14 "2019-07-12T01:56:01Z")

</div>

We don’t have a list of working vs. broken processors, but if yours is not working, then omit the `-march=native, -mtune=native`.

---

<div class="post-metadata">

**Author:** ![djvanness](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/djvanness/32/17086_2.png) [@djvanness](https://discourse.mc-stan.org/u/djvanness)\
**Post date:** [July 12, 2019, 2:08am UTC](https://discourse.mc-stan.org/t/unable-to-install-rstan-2-19-2-from-cran/9643/15 "2019-07-12T02:08:15Z")

</div>

Thanks - I think it’s a problem with g++ in rtools, which apparently predates skylake. Following information found here:

> **[It is more complicated than I thought: -mtune, -march in GCC](https://lemire.me/blog/2018/07/25/it-is-more-complicated-than-i-thought-mtune-march-in-gcc/)**
>
> My favourite C compilers are GNU GCC and LLVM’s Clang. In C, you compile for some architecture. Thus you have to tell the compiler what kind of machine you have. In theory, you could recompile all the code for the exact machine you have, but it is...

I learned that g++ thinks my processor is a broadwell. Specifying -march=broadwell -mtune=broadwell works, but -march=native -mtune=native does not. Eventually, I will test whether there is a difference in execution time of the code it compiles when the compiler march and mtune flags are left off (and presumably default to a generic option).
