RStan installation on Mac

Novice Rstan user. Updated to R4.0 and re-installed Rstan according to web instructions.
Rcpp installed no problem
** testing if installed package keeps a record of temporary installation path

Content type ‘application/x-gzip’ length 922337 bytes (900 KB)

==================================================

downloaded 900 KB

  • installing source package ‘rstan’ …

** package ‘rstan’ successfully unpacked and MD5 sums checked

** using staged installation
** libs

In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:535:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/src/Core/util/ReenableStupidWarnings.h:10:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
#pragma clang diagnostic pop
^

Simple program no longer runs

R> model_string <- "
+ data {
+   // Number of data points
+   int n1;
+   int n2;
+   // Number of successes
+   int y1[n1];
+   int y2[n2];
+ }
+ 
+ parameters {
+   real<lower=0, upper=1> theta1;
+   real<lower=0, upper=1> theta2;
+ }
+ 
+ model {  
+   theta1 ~ beta(1, 1);
+   theta2 ~ beta(1, 1);
+   y1 ~ bernoulli(theta1);
+   y2 ~ bernoulli(theta2); 
+ }
+ 
+ generated quantities {
+ }
+ "
R> y1 <- c(0, 1, 0, 0, 0, 0, 1, 0, 0, 0)
R> y2 <- c(0, 0, 1, 1, 1, 0, 1, 1, 1, 0)
R> data_list <- list(y1 = y1, y2 = y2, n1 = length(y1), n2 = length(y2))
R> 
R> library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
Keep up to date with changes at https://www.tidyverse.org/blog/
rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
R> ###### This is maybe unnecessary
R> options(mc.cores = parallel::detectCores())
R> rstan_options(auto_write = TRUE)
R> # Compiling and producing posterior samples from the model.
R> stan_samples <- stan(model_code = model_string, data = data_list)
starting worker pid=54113 on localhost:11391 at 11:24:08.911
starting worker pid=54111 on localhost:11391 at 11:24:08.911
starting worker pid=54112 on localhost:11391 at 11:24:08.911
starting worker pid=54110 on localhost:11391 at 11:24:08.911
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Execution halted
Execution halted
Execution halted
Execution halted
Error in makePSOCKcluster(names = spec, ...) : 
  Cluster setup failed. 4 of 4 workers failed to connect.

SessionInfo

R> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

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.0/Resources/lib/libRlapack.dylib

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

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

other attached packages:
[1] rstan_2.19.3         ggplot2_3.3.1        StanHeaders_2.21.0-3

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.12      pillar_1.4.4       compiler_4.0.0     prettyunits_1.1.1  tools_4.0.0        digest_0.6.25     
 [7] packrat_0.5.0      pkgbuild_1.0.8     lubridate_1.7.8    evaluate_0.14      lifecycle_0.2.0    tibble_3.0.1      
[13] gtable_0.3.0       lattice_0.20-41    pkgconfig_2.0.3    rlang_0.4.6        Matrix_1.2-18      cli_2.0.2         
[19] rstudioapi_0.11    parallel_4.0.0     yaml_2.2.1         xfun_0.14          loo_2.2.0          gridExtra_2.3     
[25] withr_2.2.0        dplyr_0.8.5        knitr_1.28         generics_0.0.2     vctrs_0.3.1        stats4_4.0.0      
[31] grid_4.0.0         tidyselect_1.1.0   glue_1.4.1         inline_0.3.15      R6_2.4.1           processx_3.4.2    
[37] fansi_0.4.1        rmarkdown_2.1      callr_3.4.3        purrr_0.3.4        magrittr_1.5       codetools_0.2-16  
[43] matrixStats_0.56.0 ps_1.3.3           scales_1.1.1       ellipsis_0.3.1     htmltools_0.4.0    assertthat_0.2.1  
[49] colorspace_1.4-1   munsell_0.5.0      crayon_1.3.4  

Thank you

Welcome to the community!

Add this to ~/.Rprofile

## WORKAROUND: https://github.com/rstudio/rstudio/issues/6692
## Revert to 'sequential' setup of PSOCK cluster in RStudio Console on macOS and R 4.0.0
if (Sys.getenv("RSTUDIO") == "1" && !nzchar(Sys.getenv("RSTUDIO_TERM")) && 
    Sys.info()["sysname"] == "Darwin") {
  parallel:::setDefaultClusterOptions(setup_strategy = "sequential")
}                   
1 Like

Changes made and it now works.
Thank you!

May the chains mix well!