# Crashing RStudio when compiling brms model

**URL:** <https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200>\
**Category:** brms\
**Created:** [April 29, 2021, 4:12pm UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200 "2021-04-29T16:12:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/pablo/32/6992_2.png) [@Pablo](https://discourse.mc-stan.org/u/Pablo)\
**Post date:** [April 29, 2021, 4:12pm UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200/1 "2021-04-29T16:12:50Z")

</div>

Hello  
I am trying to run a fairly simple logistic regression (220 datapoints, 5 variables), aiming at first to sample priors only. Here is the model

```no-highlight
prior.m1 = c(set_prior("normal(0,5)",class = "b"), 
set_prior("normal(-0.455,0.448)", class = "Intercept"))

```

```no-highlight
m1.brms=brm(formula=pres.abs~ altitude+distance+NoOfPools+NoOfSites+avrain, data=DF1s, 
            family=bernoulli, prior = prior.m1, warmup = 1000,sample_prior = "only",
            chains=4, iter=2000, control = list(adapt_delta = 0.9))  

```

When starting to compile the Stan code, RStudio (version 1.2.1335) crashes leaving me no other option than to restart another session with identical results. I reinstalled one by one brms, Rcpp, RcppEigen, RcppArmadillo to the latest versions and I obtained the same crashing results. I copy the sessionInfo() below.  
I am not suggesting that the problem lies with brms.  
I’d be thankful for any suggestions you might have.

Regards,  
Pablo

> sessionInfo()  
> R version 3.6.3 (2020-02-29)  
> Platform: x86\_64-pc-linux-gnu (64-bit)  
> Running under: Ubuntu 18.04.5 LTS

Matrix products: default  
BLAS: /usr/lib/x86\_64-linux-gnu/openblas/libblas.so.3  
LAPACK: /usr/lib/x86\_64-linux-gnu/libopenblasp-r0.2.20.so

locale:  
[1] LC\_CTYPE=en\_US.UTF-8 LC\_NUMERIC=C LC\_TIME=es\_UY.UTF-8  
[4] LC\_COLLATE=en\_US.UTF-8 LC\_MONETARY=es\_UY.UTF-8 LC\_MESSAGES=en\_US.UTF-8  
[7] LC\_PAPER=es\_UY.UTF-8 LC\_NAME=C LC\_ADDRESS=C  
[10] LC\_TELEPHONE=C LC\_MEASUREMENT=es\_UY.UTF-8 LC\_IDENTIFICATION=C

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

other attached packages:  
[1] pROC\_1.17.0.1 qqplotr\_0.0.5 DHARMa\_0.4.1 reshape2\_1.4.4 ggeffects\_1.0.2 formulaic\_0.0.8  
[7] stringi\_1.5.3 pbkrtest\_0.5.1 lme4\_1.1-26 Matrix\_1.3-2 GGally\_2.1.1 broom\_0.7.6  
[13] stringr\_1.4.0 insight\_0.13.2 future\_1.21.0 cowplot\_1.1.1 boot\_1.3-27 brms\_2.15.0  
[19] Rcpp\_1.0.6 ggplot2\_3.3.3

loaded via a namespace (and not attached):  
[1] TH.data\_1.0-10 minqa\_1.2.4 colorspace\_2.0-0 ellipsis\_0.3.1  
[5] ggridges\_0.5.3 rsconnect\_0.8.16 sjlabelled\_1.1.7 estimability\_1.3  
[9] markdown\_1.1 base64enc\_0.1-3 rstudioapi\_0.13 listenv\_0.8.0  
[13] rstan\_2.21.2 DT\_0.17 fansi\_0.4.2 mvtnorm\_1.1-1  
[17] bridgesampling\_1.1-2 codetools\_0.2-18 splines\_3.6.3 robustbase\_0.93-7  
[21] shinythemes\_1.2.0 bayesplot\_1.8.0 projpred\_2.0.2 jsonlite\_1.7.2  
[25] nloptr\_1.2.2.2 shiny\_1.6.0 compiler\_3.6.3 emmeans\_1.6.0  
[29] backports\_1.2.1 assertthat\_0.2.1 fastmap\_1.1.0 cli\_2.5.0  
[33] later\_1.1.0.1 htmltools\_0.5.1.1 prettyunits\_1.1.1 tools\_3.6.3  
[37] igraph\_1.2.6 coda\_0.19-4 gtable\_0.3.0 glue\_1.4.2  
[41] dplyr\_1.0.5 V8\_3.4.0 vctrs\_0.3.7 nlme\_3.1-152  
[45] iterators\_1.0.13 crosstalk\_1.1.1 globals\_0.14.0 ps\_1.6.0  
[49] mime\_0.10 miniUI\_0.1.1.1 lifecycle\_1.0.0 gtools\_3.8.2  
[53] statmod\_1.4.35 DEoptimR\_1.0-8 MASS\_7.3-53.1 zoo\_1.8-9  
[57] scales\_1.1.1 colourpicker\_1.1.0 promises\_1.2.0.1 Brobdingnag\_1.2-6  
[61] sandwich\_3.0-0 parallel\_3.6.3 inline\_0.3.17 RColorBrewer\_1.1-2  
[65] shinystan\_2.5.0 gamm4\_0.2-6 curl\_4.3 gridExtra\_2.3  
[69] loo\_2.4.1 StanHeaders\_2.21.0-7 reshape\_0.8.8 dygraphs\_1.1.1.6  
[73] foreach\_1.5.1 pkgbuild\_1.2.0 rlang\_0.4.10 pkgconfig\_2.0.3  
[77] matrixStats\_0.58.0 lattice\_0.20-41 purrr\_0.3.4 rstantools\_2.1.1  
[81] htmlwidgets\_1.5.3 tidyselect\_1.1.0 processx\_3.5.1 parallelly\_1.24.0  
[85] plyr\_1.8.6 magrittr\_2.0.1 R6\_2.5.0 generics\_0.1.0  
[89] multcomp\_1.4-16 DBI\_1.1.1 pillar\_1.6.0 withr\_2.4.2  
[93] mgcv\_1.8-34 xts\_0.12.1 survival\_3.2-10 abind\_1.4-5  
[97] tibble\_3.1.1 crayon\_1.4.1 utf8\_1.2.1 grid\_3.6.3  
[101] data.table\_1.14.0 callr\_3.6.0 threejs\_0.3.3 digest\_0.6.27  
[105] xtable\_1.8-4 tidyr\_1.1.3 httpuv\_1.5.5 RcppParallel\_5.1.2  
[109] stats4\_3.6.3 munsell\_0.5.0 shinyjs\_2.0.0

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [May 3, 2021, 11:30pm UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200/2 "2021-05-03T23:30:57Z")

</div>

Hi Pablo,

Crashing R is usually related to rstan in this context. Does your session also crash if you run the RStan example model:

```r
example(stan_model,package="rstan",run.dontrun=T)

```

---

<div class="post-metadata">

**Author:** ![Pablo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/pablo/32/6992_2.png) [@Pablo](https://discourse.mc-stan.org/u/Pablo)\
**Post date:** [May 4, 2021, 12:02am UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200/3 "2021-05-04T00:02:46Z")

</div>

Hello,  
Thanks for the response.  
R does not now crash when I run:  
example(stan\_model,package=“rstan”,run.dontrun=T)

A few hours after my somewhat desperate message, I chose to do the “brute force” approach of uninstalling reinstalling R 3.6.0 from scratch and updating every R library. My crashing of rstan seems to have been caused by missing specialized numerical libraries that are required in Linux Ubuntu to install rstan, brms and other R libraries. Sometimes these libraries popup when installing or updating R libraries and they can be installed from the Linux terminal. I presume that something went wrong during my updatings of these numerical libraries in Linux that caused rstan to make R crash.  
Everything works fine now.  
Many thanks again,  
Cheers  
Pablo

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [May 4, 2021, 12:21am UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200/4 "2021-05-04T00:21:01Z")

</div>

Great to hear that it’s all working!

---

<div class="post-metadata">

**Author:** ![tiflo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/tiflo/32/3044_2.png) [@tiflo](https://discourse.mc-stan.org/u/tiflo)\
**Post date:** [June 13, 2023, 11:04pm UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200/5 "2023-06-13T23:04:47Z")

</div>

Hi,

I’m reviving this thread since R (4.3.0) and/or RStudio (most recent built 2023.06.0 Build 421) crashes every time the compiler is evoked, including for:

> [@andrjohns](#):
>
> `example(stan_model,package="rstan",run.dontrun=T)`

I just reinstalled the toolchain (xcode CLI, GCC/gfortran, and other R binaries) from scratch but I’m still having the same problem. Any pointers would be appreciated!

```no-highlight
platform aarch64-apple-darwin20      
arch aarch64                     
os darwin20                    
system aarch64, darwin20           
status                                     
major 4                           
minor 3.0                         
year 2023                        
month 04                          
day 21                          
svn rev 84292                       
language R                           
version.string R version 4.3.0 (2023-04-21)
nickname Already Tomorrow

```

with rstan version 2.21.8.

When I run the example in R, the compilation starts and then a prompt “Selection:” appears (while the compilation holds). No options are listed. If I enter “1”, R crashes. The first few lines of the crash report read:

```no-highlight
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 file155f374480d9.so 0x103d84524 stan::math::stack_alloc::alloc(unsigned long) + 0 (stack_alloc.hpp:171) [inlined]
1 file155f374480d9.so 0x103d84524 stan::math::vari::operator new(unsigned long) + 12 (vari.hpp:127) [inlined]
2 file155f374480d9.so 0x103d84524 stan::math::var::var(double) + 12 (var.hpp:90) [inlined]
3 file155f374480d9.so 0x103d84524 stan::math::var::var(double) + 12 (var.hpp:90) [inlined]
4 file155f374480d9.so 0x103d84524 double stan::model::log_prob_grad<true, true, stan::model::model_base>(stan::model::model_base const&, std:: __1::vector<double, std::__ 1::allocator<double>>&, std:: __1::vector<int, std::__ 1::allocator<int>>&, std:: __1::vector<double, std::__ 1::allocator<double>>&, std:: __1::basic_ostream<char, std::__ 1::char_traits<char>>*) + 164 (log_prob_grad.hpp:38)

```

---

<div class="post-metadata">

**Author:** ![R\_V](https://avatars.discourse-cdn.com/v4/letter/r/7993a0/32.png) [@R\_V](https://discourse.mc-stan.org/u/R_V)\
**Post date:** [June 14, 2023, 10:47am UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200/6 "2023-06-14T10:47:34Z")

</div>

I have experienced crashes this morning on my Mac and I managed to solve the problem by reinstalling RStan from source. See here:

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

[the installation of the development version of RStan from GitHub did not work for me, but it did work with the CRAN version]

---

<div class="post-metadata">

**Author:** ![tiflo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/tiflo/32/3044_2.png) [@tiflo](https://discourse.mc-stan.org/u/tiflo)\
**Post date:** [June 14, 2023, 1:54pm UTC](https://discourse.mc-stan.org/t/crashing-rstudio-when-compiling-brms-model/22200/7 "2023-06-14T13:54:58Z")

</div>

> [@andrjohns](#):
>
> example(stan\_model,package=“rstan”,run.dontrun=T)

That did the trick! Thank you @R_V !
