R and RStudio crashing during sampling phase of the stan execution

I am completely new to stan and recently attended an rstan workshop with amongst others @paul.buerkner demonstrating his brms package.

My problems in a nutshell is that R and RStudio crashes during sampling phase of the stan execution when running the following code.

	library(brms)
	# options(mc.cores = parallel::detectCores())
	# rstan_options(auto_write = TRUE)
	
	url <- "https://raw.githubusercontent.com/mages/diesunddas/master/Data/ClarkTriangle.csv"
	loss <- read.csv(url)
	loss$LR = with(loss, cum / premium)
	head(loss)
	
	fit_loss <- brm(
	    bf(LR ~ ult * (1 - exp(-(dev/theta)^omega)),
	       ult ~ 1 + (1|AY), omega ~ 1, theta ~ 1, 
	       nl = TRUE),
	    data = loss, family = gaussian(),
	    prior = c(
	        prior(lognormal(log(0.5), 0.3), nlpar = "ult", lb = 0),
	        prior(normal(1, 2), nlpar = "omega", lb = 0),
	        prior(normal(45, 10), nlpar = "theta", lb = 0)
	    ),
	    cores = 1, chains = 1
	    # control = list(adapt_delta = 0.9)
	)

When running the code, I can see that the stan model is being compiled and the first SAMPLING FOR MODEL … (Chain 1) is started.
Within about 20 seconds of this happening RStudio aborts the session. If I run the same code within the native R console, I get to the same execution point, but the R console just hangs as if the code fails silently in the background.

@paul.buerkner suggested a variety of simplifications to the code, such as setting cores = 1, and chains = 1

This is what is output to the console:

	Compiling the C++ model
	Start sampling
	
	SAMPLING FOR MODEL 'gaussian brms-model' NOW (CHAIN 1).
	
	Gradient evaluation took 0 seconds
	1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
	Adjust your expectations accordingly!

	Iteration:    1 / 2000 [  0%]  (Warmup)
  • I have tried this in 3 different windows environments, a windows laptop (Windows 8), a windows PC (windows 8) and finally a windows server 2012 all exhibiting the same problem.
    The session info is for the windows server, as this has the highest spec (2.3 GHz, 24 cores, 512Gb RAM)

  • I have tried this using rstan version 2.17.3 on all 3.

  • I have also tried to download the binaries and install rstan (2.17.2) on the server and laptop

  • All 3 environments have differnt versions of R and corresponding versions of RTools.

    • Windows Laptop: R version 3.5.1 (2018-07-02)
    • Windows PC: R version 3.4.0 Patched (2017-05-08 r72665)
    • Windows Server: R version 3.4.3 (2017-11-30)
  • I can successfully run a simple stan models such as:

      library(rstan)
      rstan_options(auto_write = TRUE)
      options(mc.cores = parallel::detectCores())
    
      scode <- "
      parameters {
          real y[2];
      }
      model {
          y[1] ~ normal(0, 1);
          y[2] ~ double_exponential(0, 2);
      }
      "
      
      fit1 <- stan(model_code = scode, iter = 10, verbose = FALSE)
      print(fit1)
    

And get the following output:

In file included from C:/Users/my_user/Documents/R/win-library/3.4/BH/include/boost/config.hpp:39:0,
                 from C:/Users/my_user/Documents/R/win-library/3.4/BH/include/boost/math/tools/config.hpp:13,
                 from C:/Users/my_user/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core/var.hpp:7,
                 from C:/Users/my_user/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
                 from C:/Users/my_user/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core.hpp:12,
                 from C:/Users/my_user/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/my_user/Documents/R/win-library/3.4/StanHeaders/include/stan/math.hpp:4,
                 from C:/Users/my_user/Documents/R/win-library/3.4/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file3e3412e77ce8.cpp:8:
C:/Users/my_user/Documents/R/win-library/3.4/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined
 #  define BOOST_NO_CXX11_RVALUE_REFERENCES
 ^
<command-line>:0:0: note: this is the location of the previous definition
cc1plus.exe: warning: unrecognized command line option "-Wno-ignored-attributes"
Loading required namespace: rstudioapi
> print(fit1)
Inference for Stan model: 0f459bda2e2707c0379d5ca819627502.
4 chains, each with iter=10; warmup=5; thin=1; 
post-warmup draws per chain=5, total post-warmup draws=20.

      mean se_mean   sd  2.5%   25%   50%   75% 97.5% n_eff Rhat
y[1]  0.21    0.31 1.38 -1.74 -0.97  0.42  1.22  2.35    20 1.00
y[2]  0.17    0.82 1.67 -2.62 -0.75  0.18  1.31  2.97     4 1.23
lp__ -1.63    0.27 0.85 -3.43 -1.94 -1.46 -0.98 -0.61    10 1.18

Samples were drawn using NUTS(diag_e) at Wed Jul 18 10:36:20 2018.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).
  • Operating System: Windows Server 2012

  • RStan Version: 2.17.3 and (2.17.2 also tried)

  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))

      writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))	
      CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function	
      CXXFLAGS += -Wno-ignored-attributes -Wno-deprecated-declarations
    
  • Output of devtools::session_info("rstan")

      devtools::session_info("rstan")
      Session info ---------------------------------------------------------------------------------------------------------------------
       setting  value                       
       version  R version 3.4.3 (2017-11-30)
       system   x86_64, mingw32             
       ui       RStudio (1.1.423)           
       language (EN)                        
       collate  English_United Kingdom.1252 
       tz       Europe/London               
       date     2018-07-17                  
      Packages -------------------------------------------------------------------------------------------------------------------------
       package      * version   date       source        
       assertthat     0.2.0     2017-04-11 CRAN (R 3.4.2)
       BH             1.65.0-1  2017-08-24 CRAN (R 3.4.1)
       cli            1.0.0     2017-11-05 CRAN (R 3.4.3)
       colorspace     1.3-2     2016-12-14 CRAN (R 3.4.2)
       crayon         1.3.4     2017-09-16 CRAN (R 3.4.2)
       dichromat      2.0-0     2013-01-24 CRAN (R 3.4.1)
       digest         0.6.13    2017-12-14 CRAN (R 3.4.3)
       ggplot2      * 2.2.1     2016-12-30 CRAN (R 3.4.3)
       graphics     * 3.4.3     2018-01-10 local         
       grDevices    * 3.4.3     2018-01-10 local         
       grid           3.4.3     2018-01-10 local         
       gridExtra      2.3       2017-09-09 CRAN (R 3.4.2)
       gtable         0.2.0     2016-02-26 CRAN (R 3.4.2)
       inline         0.3.14    2015-04-13 CRAN (R 3.4.3)
       labeling       0.3       2014-08-23 CRAN (R 3.4.1)
       lattice        0.20-35   2017-03-25 CRAN (R 3.4.3)
       lazyeval       0.2.1     2017-10-29 CRAN (R 3.4.3)
       magrittr       1.5       2014-11-22 CRAN (R 3.4.2)
       MASS           7.3-47    2017-02-26 CRAN (R 3.4.3)
       Matrix         1.2-12    2017-11-20 CRAN (R 3.4.3)
       methods      * 3.4.3     2018-01-10 local         
       munsell        0.4.3     2016-02-13 CRAN (R 3.4.2)
       pillar         1.0.1     2017-11-27 CRAN (R 3.4.3)
       plyr           1.8.4     2016-06-08 CRAN (R 3.4.2)
       R6             2.2.2     2017-06-17 CRAN (R 3.4.2)
       RColorBrewer   1.1-2     2014-12-07 CRAN (R 3.4.1)
       Rcpp         * 0.12.14   2017-11-23 CRAN (R 3.4.3)
       RcppEigen      0.3.3.3.1 2017-11-20 CRAN (R 3.4.3)
       reshape2       1.4.3     2017-12-11 CRAN (R 3.4.3)
       rlang          0.1.6     2017-12-21 CRAN (R 3.4.3)
       rstan          2.17.2    2017-12-21 CRAN (R 3.4.3)
       scales         0.5.0     2017-08-24 CRAN (R 3.4.2)
       StanHeaders    2.17.1    2017-12-20 CRAN (R 3.4.3)
       stats        * 3.4.3     2018-01-10 local         
       stats4         3.4.3     2018-01-10 local         
       stringi        1.1.6     2017-11-17 CRAN (R 3.4.2)
       stringr        1.2.0     2017-02-18 CRAN (R 3.4.2)
       tibble         1.4.1     2017-12-25 CRAN (R 3.4.3)
       tools          3.4.3     2018-01-10 local         
       utf8           1.1.2     2017-12-14 CRAN (R 3.4.3)
       utils        * 3.4.3     2018-01-10 local         
       viridisLite    0.2.0     2017-03-24 CRAN (R 3.4.2)
    

Thanks in advance

This example is working on the only Windows machine I have access to. It is weird that you can do some models but not this one. Perhaps there is someone else on Discourse who can replicate this problem?