Crashing RStudio when compiling brms model

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

prior.m1 = c(set_prior("normal(0,5)",class = "b"), 
set_prior("normal(-0.455,0.448)", class = "Intercept"))
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

Hi Pablo,

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

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

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

1 Like

Great to hear that it’s all working!

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:

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!

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:

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)

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

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

1 Like

That did the trick! Thank you @R_V !