Rstan on Windows

Sorry for the hassle! I’m not sure what’s going on here either. @bgoodri @bbbales2 or @wds15 any ideas?

I read through the errors but it’s not ringing any bells.

Searching for the string I saw this post which is dealing with a similar error: Installation issue

Thanks, I’ll take a look and see what I can do!

Wow that did the trick! Thanks to all of you for helping me get up and running, I’m very appreciative of it!

2 Likes

@graham Glad it’s working! @bbbales2 thanks for tracking that down.

@stevebronder Any progress on the patch for this error?

It was just reported again on the rstan issue tracker:

I just wanted to jump in an confirm that this is still an issue for me. The weird thing is, sometimes R studio simply crashes with the “C stack trace error” even I simply subset my data. I also notice that when stan is running in a loop (to fit multiple datasets to the same model), once it works, it will work and will not crash. My solution so far is to simply keep rerunning Rstudio hoping it will make it to the stan part.

Alex
(PS: not sure if it is coincidental, but my code hasn’t crashed (yet) since I removed my generated quantities block, where I compute the log likelihood used to compute the LOOIC and WAIC later in the R code…)

1 Like

@avdminne Thanks for letting us know that’s still an issue. A few comments/questions:

Can you share what’s in your Makevars.win file? You can check with

file.edit(file.path(Sys.getenv("HOME"), ".R", "Makevars.win"))

If there’s anything in there I would try deleting it all and just using
CXX14FLAGS=-O3 -mtune=native.

Are you using repeated calls to the stan() function or are you compiling first with stan_model() and then calling sampling() repeatedly?

Finally, if we can’t figure out how to get it running for you without you having to always worry it’s going to crash, then I recommend tryinng the new CmdStanR interface, which shouldn’t have that issue. (If you try that and run into any trouble installing on Windows let us know and we can definitely fix that issue)

1 Like

the URLs are actually not valid. When trying to run these commands (for R4.0) both yield a 404

Hi @etaifour, I don’t think the links are needed anymore. Can you try just using install.packages("rstan", dependencies = TRUE)?

Thanks, you are right, it seems they are not needed anymore. I have just ran the command you have shared, and did not receive any errors.
I then loaded rstan, and ran the schools.stan “hello world” program (from the documentation). I was able to print/plot the fitted models.

Thanks for your help
rEgards, Eyas

Great, glad it’s working!

I couldn’t replicate the issue on my linux machine. I can spin up a windows instance tmrw and try this again

1 Like

BTW… we need to include in our instructions to more frequently restart R. This comes up really often that people forget that.

1 Like

Hi Jonah,

I make a stan_model() first, and subsequently use sampling(). (I learned that the hard way as well.) As for my Makevars, I deleted everything that was in the file. It was a recommendation I got earlier… So I guess I don’t have to show the actual file then, right?

It hasn’t crashed for a full 24h now, so that is reassuring, but I will definitely try out CmdStanR. Many thanks.

2 Likes

Yeah emptying the Makevars file is a good idea when troubleshooting, but now that it’s working I suggest adding just this line

to Makevars which should make Stan a decent bit faster.

Anyway, glad it’s not crashing at the moment. And if you give CmdStanR a try let us know if you run into any trouble.

Hi everyone,

I just updated R and rstan yesterday. One of my models that was running fine the day before is not running anymore. I get the next error and warning messages:

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 fileba824601f4c.cpp 2> fileba824601f4c.cpp.err.txt' had status 1
3: In file(con, "r") :
  cannot open file 'fileba824601f4c.cpp.err.txt': No such file or directory
Error in sink(type = "output") : invalid connection

I am running on widows and using :
R version 4.0.2
Platform x86_64-w64-mingw32/x64 (64-bit)
rstan 2.21.2

I did double check that the model is in the right working directory and I tried with one of the examples form the Stan manual. I get the same error and warning messages.

Any ideas?

Cheers,
Alfonso

I’m having a similar issue with rstan.
session

> sessionInfo()
R version 4.0.2 (2020-06-22)
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  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.21.2         ggplot2_3.3.2        StanHeaders_2.21.0-5

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5         compiler_4.0.2     pillar_1.4.6       prettyunits_1.1.1  tools_4.0.2       
 [6] pkgbuild_1.1.0     jsonlite_1.7.0     lifecycle_0.2.0    tibble_3.0.3       gtable_0.3.0      
[11] pkgconfig_2.0.3    rlang_0.4.7        cli_2.0.2          rstudioapi_0.11    parallel_4.0.2    
[16] curl_4.3           loo_2.3.1          gridExtra_2.3      dplyr_1.0.1        withr_2.2.0       
[21] generics_0.0.2     vctrs_0.3.2        tidyselect_1.1.0   stats4_4.0.2       grid_4.0.2        
[26] glue_1.4.1         inline_0.3.15      R6_2.4.1           processx_3.4.3     fansi_0.4.1       
[31] purrr_0.3.4        callr_3.4.3        magrittr_1.5       codetools_0.2-16   matrixStats_0.56.0
[36] scales_1.1.1       ps_1.3.3           ellipsis_0.3.1     assertthat_0.2.1   colorspace_1.4-1  
[41] V8_3.2.0           RcppParallel_5.0.2 munsell_0.5.0      crayon_1.3.4  

error message when I run

example(stan_model, package = "rstan", run.dontrun = TRUE)
Compilation argument:
 C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file76b056351fea.cpp 2> file76b056351fea.cpp.err.txt 
"C:/rtools40/mingw64/bin/"g++  -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG   -I"C:/Program Files/R/R-4.0.2/library/Rcpp/include/"  -I"C:/Program Files/R/R-4.0.2/library/RcppEigen/include/"  -I"C:/Program Files/R/R-4.0.2/library/RcppEigen/include/unsupported"  -I"C:/Program Files/R/R-4.0.2/library/BH/include" -I"C:/Program Files/R/R-4.0.2/library/StanHeaders/include/src/"  -I"C:/Program Files/R/R-4.0.2/library/StanHeaders/include/"  -I"C:/Program Files/R/R-4.0.2/library/RcppParallel/include/"  -I"C:/Program Files/R/R-4.0.2/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include "C:/Program Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp"  -std=c++1y       -include C:/Program Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I "C:/Program Files/R/R-4.0.2/library/StanHeaders/include" -I "C:/Program Files/R/R-4.0.2/library/RcppEigen/include"   -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c file76b056351fea.cpp -o file76b056351fea.o
g++.exe: error: Files/R/R-4.0.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: file76b056351fea.o] Error 1
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:/rtools40/usr/mingw_/bin/g++' not found
2: In file(con, "r") :
  cannot open file 'file76b056351fea.cpp.err.txt': No such file or directory

Makevars

CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2
CXX14 = C:/rtools40/mingw64/bin/g++

also tried, same error

CXX14 = C:/rtools40/mingw$(WIN)/bin/g++
and
CXX14 = C:/rtools40/usr/mingw_$(WIN)/bin/g++

What about if you set

CXX14 = C:/rtools40/mingw64/bin/g++

or

CXX14 = C:/rtools40/mingw_64/bin/g++

Though I think the former is the correct one, at least on two Windows machine I have Rtools 4.0 installed.

that’s what I have in makevars

CXX14 = C:/rtools40/mingw64/bin/g++

and checking the folder