R for Windows GUI front-end has stopped working, in for loops


Dear all,

I have been running into a rather big issue while using rstan, and that is that it keeps crashing R when going through loops. During the first iteration it never crashes, but as I go through my loop (I fit several models to several datasets) R will stop, prompting “R for Windos GUI fron-end has stopped working”. This does not necessarily happens during the second iteration, but rather randomly. I have tried other GUIs (like Rstudio and commander), I have tried different versions of R and Rtools, I have even tried to run it on different computers. I cannot really give reproducible code, but I noticed it happens any time I call rstan in succession in a loop (even with a completely different research I am working on, but with added loops). The moment of the crash is exactly when rstan starts (I put a bunch of print statements in there to see when it happens) or rather restarts. Unfortunately, R gives me no other information - other than it crashed (thanks) - so I have no idea how to resolve this.

I do store interim results.If I keep restarting R, it therefore does finish everything I want in the end. However, it is rather annoying (although this does `proof’ that there is no real bug in the code).

Do you know any way that I can get more details of what is happening? Is there a way for me to work around it? I cannot seem to find anything about this online…
Sorry for the vague question, but hopefully you can help me in one way or the other…

Operating System: Windows 10
Interface Version: R-GUI
Output of writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”))):
Output of devtools::session_info("rstan”):
Session info -------------------------------------------------------------------------------------------------------------
setting value
version R version 3.4.0 (2017-04-21)
system x86_64, mingw32
ui Rgui
language (EN)
collate English_United States.1252
tz America/New_York
date 2017-05-18

Packages -----------------------------------------------------------------------------------------------------------------
package * version date source
BH 1.62.0-1 2016-11-19 CRAN (R 3.4.0)
colorspace 1.3-2 2016-12-14 CRAN (R 3.4.0)
dichromat 2.0-0 2013-01-24 CRAN (R 3.4.0)
digest 0.6.12 2017-01-27 CRAN (R 3.4.0)
ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.0)
graphics * 3.4.0 2017-04-21 local
grDevices * 3.4.0 2017-04-21 local
grid 3.4.0 2017-04-21 local
gridExtra 2.2.1 2016-02-29 CRAN (R 3.4.0)
gtable 0.2.0 2016-02-26 CRAN (R 3.4.0)
inline 0.3.14 2015-04-13 CRAN (R 3.4.0)
labeling 0.3 2014-08-23 CRAN (R 3.4.0)
lattice 0.20-35 2017-03-25 CRAN (R 3.4.0)
lazyeval 0.2.0 2016-06-12 CRAN (R 3.4.0)
magrittr 1.5 2014-11-22 CRAN (R 3.4.0)
MASS 7.3-47 2017-02-26 CRAN (R 3.4.0)
Matrix 1.2-9 2017-03-14 CRAN (R 3.4.0)
methods * 3.4.0 2017-04-21 local
munsell 0.4.3 2016-02-13 CRAN (R 3.4.0)
plyr 1.8.4 2016-06-08 CRAN (R 3.4.0)
RColorBrewer 1.1-2 2014-12-07 CRAN (R 3.4.0)
Rcpp 0.12.10 2017-03-19 CRAN (R 3.4.0)
RcppEigen 2017-05-01 CRAN (R 3.4.0)
reshape2 1.4.2 2016-10-22 CRAN (R 3.4.0)
rstan * 2.15.1 2017-04-19 CRAN (R 3.4.0)
scales 0.4.1 2016-11-09 CRAN (R 3.4.0)
StanHeaders * 2.15.0-1 2017-04-19 CRAN (R 3.4.0)
stats * 3.4.0 2017-04-21 local
stats4 3.4.0 2017-04-21 local
stringi 1.1.5 2017-04-07 CRAN (R 3.4.0)
stringr 1.2.0 2017-02-18 CRAN (R 3.4.0)
tibble 1.3.0 2017-04-01 CRAN (R 3.4.0)
tools 3.4.0 2017-04-21 local
utils * 3.4.0 2017-04-21 local


There is not much we can do to diagnose failures that are not predictable. You might try running your script from Rterm instead of Rgui to see if there is more to the error message. Also, make sure that you no longer have -mtune=native -march=native in ~/.R/Makevars .


On windows it happens when you switch from one PC to another. I delete rds (or whatever is its name) file generated by stan compiler so it compiles the model again. It saves a lot of frustration.


Actually, I did write the code on my laptop and subsequently put it on a workstation via remote access. I even changed the code there and put it back on my laptop, etc. (+ I work on Windows on both machines) So this could be it. However, I deleted my temp files (I believe this is were it is automatically written to?) and put auto_write = FALSE, to be sure. However, it still crashes after 1 or 2 loops.

Any other suggestions?
Many thanks,


Dear Ben,

Thanks for your input.
After running it in Rterm it still crashed on my laptop (R version 3.3.1). It did run longer than usual, but that might be luck. However, on the work station (R version 3.4.0) I noticed the following warning;

“recompiling to avoid crashing R session”

I did not notice this warning when using Rgui on the work station (might have missed it). Rterm on the work station is still running, so it might still crash. However, I was hoping that this gives an indication of what is going on. I could not find a simple solution online unfortunately, except that it has to do with .DLL files that get overwritten.

Many thanks!


That message comes when there either has been some change to the Stan program since the last time it was called or else the container that held the DLL gets garbage collected. Which of those holds in your case?


Once in a while it crashes on me as well. Very annoying. But when I delete .rds and run stan again it doesn’t crash for some time. I switched to cmd stan and NEVER experienced a problem. I run cmd stan from R and delete compiled file to make sure that I start from scratch. Technically there could be a problem with large files when reading csv generated by cmd stan or some other exception.