Example in rstan::sampling() crashes R completely on Mac OSX

When trying to run the basic example in sampling(), using RStudio (v. 2022.02.03):

m <- stan_model(model_code = 'parameters {real y;} model {y ~ normal(0,1);}')
f <- sampling(m, iter = 100)

the model itself compiles, but the call to sampling() crashes immediately, with RStudio saying the session was aborted.

Here is what I tried based on other posts online:

  • Reinstalling R and Rstudio
  • Running the code in base R instead of RStudio
  • Reinstalling rstan and its dependencies after deleting the existing folders for rstan and the various Rcpp dependencies in .libPaths()

Here’s my sessionInfo:

R version 4.2.0 (2022-04-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.0.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] rstan_2.21.5         ggplot2_3.3.6        StanHeaders_2.21.0-7

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3       pillar_1.7.0       compiler_4.2.0     prettyunits_1.1.1  tools_4.2.0        pkgbuild_1.3.1    
 [7] lifecycle_1.0.1    tibble_3.1.7       gtable_0.3.0       pkgconfig_2.0.3    rlang_1.0.2        cli_3.3.0         
[13] parallel_4.2.0     loo_2.5.1          gridExtra_2.3      withr_2.5.0        dplyr_1.0.9        generics_0.1.2    
[19] vctrs_0.4.1        stats4_4.2.0       grid_4.2.0         tidyselect_1.1.2   glue_1.6.2         inline_0.3.19     
[25] R6_2.5.1           processx_3.6.0     fansi_1.0.3        purrr_0.3.4        callr_3.7.0        magrittr_2.0.3    
[31] codetools_0.2-18   scales_1.2.0       ps_1.7.0           ellipsis_0.3.2     matrixStats_0.62.0 colorspace_2.0-3  
[37] utf8_1.2.2         RcppParallel_5.1.5 munsell_0.5.0      crayon_1.5.1   

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

loaded via a namespace (and not attached):
[1] compiler_4.2.0 tools_4.2.0 

Hi and welcome to the community!

I use the same RStudio, StanHeaders, and rstan versions with R 4.2.0 and it works for me. I use OSX 12.4. My gcc --version gives me this:

Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Perhaps try R Interface to CmdStan • cmdstanr instead?

I have the same issue with rstan once the sampling starts R(Studio) crashes. I can run my simple programs using cmdstanr (am a fairly novice user) so this is not a major issue but I’m just persistent and like to understand what’s going on with rstan. Have removed and re-installed with no luck.
Here is my session info

R> rstan_options(auto_write = FALSE)
R> sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.4.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Toronto
tzcode source: internal

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

other attached packages:
[1] rstan_2.21.8        ggplot2_3.4.2       StanHeaders_2.26.27 cmdstanr_0.5.3     

loaded via a namespace (and not attached):
 [1] tensorA_0.36.2       utf8_1.2.3           generics_0.1.3       magrittr_2.0.3       grid_4.3.1          
 [6] jsonlite_1.8.5       processx_3.8.1       pkgbuild_1.4.2       backports_1.4.1      ps_1.7.5            
[11] gridExtra_2.3        fansi_1.0.4          scales_1.2.1         codetools_0.2-19     abind_1.4-5         
[16] cli_3.6.1            rlang_1.1.1          crayon_1.5.2         munsell_0.5.0        withr_2.5.0         
[21] tools_4.3.1          inline_0.3.19        parallel_4.3.1       checkmate_2.2.0      dplyr_1.1.2         
[26] colorspace_2.1-0     pacman_0.5.1         vctrs_0.6.3          posterior_1.4.1      R6_2.5.1            
[31] matrixStats_1.0.0    stats4_4.3.1         lifecycle_1.0.3      pkgconfig_2.0.3      callr_3.7.3         
[36] RcppParallel_5.1.7   pillar_1.9.0         gtable_0.3.3         loo_2.6.0            data.table_1.14.8   
[41] glue_1.6.2           Rcpp_1.0.10          xfun_0.39            tibble_3.2.1         tidyselect_1.2.0    
[46] rstudioapi_0.14      knitr_1.43           farver_2.1.1         compiler_4.3.1       prettyunits_1.1.1   
[51] distributional_0.3.2