Install Windows 10 with Rstudio

Hello,
I am new to Stan and am trying to get Stan working before a workshop I plan to attend.
I am following along with installation, https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started all seems well, until I try and run the sample code in which I get:

install.packages(“rstan”, repos = “https://cloud.r-project.org/”, dependencies = TRUE)
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/R’
(as ‘lib’ is unspecified)
trying URL ‘https://cloud.r-project.org/bin/windows/contrib/3.6/rstan_2.18.2.zip
Content type ‘application/zip’ length 4451314 bytes (4.2 MB)
downloaded 4.2 MB

package ‘rstan’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\kapitull\AppData\Local\Temp\RtmpmesDjx\downloaded_packages

pkgbuild::has_build_tools(debug = TRUE)
trying URL ‘https://cran.rstudio.com/bin/windows/Rtools/Rtools35.exe
Content type ‘application/x-msdownload’ length 108622512 bytes (103.6 MB)
downloaded 103.6 MB

[1] FALSE

pkgbuild::has_build_tools(debug = TRUE)
[1] TRUE
library(“rstan”) # observe startup messages
Loading required package: ggplot2
Registered S3 methods overwritten by ‘ggplot2’:
method from
[.quosures rlang
c.quosures rlang
print.quosures rlang
Loading required package: StanHeaders
rstan (Version 2.18.2, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
For improved execution time, we recommend calling
Sys.setenv(LOCAL_CPPFLAGS = ‘-march=native’)
although this causes Stan to throw an error on a few processors.
rstan_options(auto_write = TRUE)
schools_dat <- list(J = 8,

  •                 y = c(28,  8, -3,  7, -1,  1, 18, 12),
    
  •                 sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
    

fit <- stan(file = ‘8schools.stan’, data = schools_dat)
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
Execution halted
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/R/bin/x64/R CMD SHLIB file34d462f6668e.cpp 2> file34d462f6668e.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection
setwd(“c:/R/work”)
fit <- stan(file = ‘8schools.stan’, data = schools_dat)
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
Execution halted
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/R/bin/x64/R CMD SHLIB file34d430f6ab8.cpp 2> file34d430f6ab8.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

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

1 Like

Thank you so very much, that did indeed fix it.
I appreciate your kindness in taking the time to point out to me where to find help with this problem.

For those who might have been a bit confused at first like I was when they read the thread above, I will post my quick summary below:

Ultimately, I just had to open the file makevars.win in my .R directory, I used notepad to do this, then I deleted what was in there and replace it with the line of code below:

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

I did not even have to restart Rstudio, on my machine.

After making that change I just reran
fit <- stan(file = ‘c:/R/work/8schools.stan’, data = schools_dat)

It took a little bit of time to run on my machine, 20 seconds maybe, but I did get output and now feel ready for my workshop.

Again thank you. I love when people save me time and are kind about it :)

2 Likes