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

[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.
Target: x86_64-apple-darwin21.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Perhaps try R Interface to CmdStan • cmdstanr instead?