Problem with running brms Mac OS X with R 4.0

I upgraded to R 4.0, and this has apparently broken my entire Stan-related workflow.

I posted earlier about my problems with rstan, but these are partially resolved, as discussed in this thread:

I am now trying to install and run brms. I simply did

install.packages(“brms”)

.R/Makevars and .Renviron were removed a few hrs ago as advised by Stephen Martin’s post on R 4.0.

brms seemed to install. Then I tested it:

> bprior1 <- prior(student_t(5,0,10), class = b) +
+        prior(cauchy(0,2), class = sd)
>      fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
+                  data = epilepsy, family = poisson(), prior = bprior1)
Compiling the C++ model
Fehler in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:82:
In file included from /Users/shravanvasishth/miniconda3/bin/../include/c++/v1/new:89:
In file included from /Users/shravanvasishth/miniconda3/bin/../include/c++/v1/exception:82:
In file included from /Users/shravanvasishth/miniconda3/bin/../include/c++/v1/cstdlib:86:
/Users/shravanvasishth/miniconda3/bin/../include/c++/v1/stdlib.h:94:15: fatal error: 'stdlib.h' file not found
#include_next <stdlib.h>
              ^~~~~~~~~~
1 error generated.
make: *** [file15b8405e4419.o] Error 1
Zusätzlich: Warnmeldung:
In system(cmd, intern = !verbose) :
  Ausführung von Kommando '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file15b8405e4419.cpp 2> file15b8405e4419.cpp.err.txt' ergab Status 1
Fehler in sink(type = "output") : ungültige Verbindung
> 

Any advice on fixing this is appreciated.

  • Operating System

OS: Mac, 10.14.6 Mojave

  • RStan Version

2.19.3

R version 4.0.0 (2020-04-24) – “Arbor Day”

devtools::session_info(“brms”)
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.0.0 (2020-04-24)
os macOS Mojave 10.14.6
system x86_64, darwin17.0
ui X11
language (EN)
collate C
ctype UTF-8
tz Europe/Berlin
date 2020-05-05

─ Packages ───────────────────────────────────────────────────────────────────
package * version date lib source
abind 1.4-5 2016-07-21 [1] CRAN (R 4.0.0)
askpass 1.1 2019-01-13 [1] CRAN (R 4.0.0)
assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.0)
backports 1.1.6 2020-04-05 [1] CRAN (R 4.0.0)
base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.0.0)
bayesplot 1.7.1 2019-12-01 [1] CRAN (R 4.0.0)
BH 1.72.0-3 2020-01-08 [1] CRAN (R 4.0.0)
bridgesampling 1.0-0 2020-02-26 [1] CRAN (R 4.0.0)
brms * 2.12.0 2020-02-23 [1] CRAN (R 4.0.0)
Brobdingnag 1.2-6 2018-08-13 [1] CRAN (R 4.0.0)
callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.0)
checkmate 2.0.0 2020-02-06 [1] CRAN (R 4.0.0)
cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.0)
coda 0.19-3 2019-07-05 [1] CRAN (R 4.0.0)
codetools 0.2-16 2018-12-24 [1] CRAN (R 4.0.0)
colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.0)
colourpicker 1.0 2017-09-27 [1] CRAN (R 4.0.0)
crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.0)
crosstalk 1.1.0.1 2020-03-13 [1] CRAN (R 4.0.0)
curl 4.3 2019-12-02 [1] CRAN (R 4.0.0)
desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.0)
digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.0)
dplyr 0.8.5 2020-03-07 [1] CRAN (R 4.0.0)
DT 0.13 2020-03-23 [1] CRAN (R 4.0.0)
dygraphs 1.1.1.6 2018-07-11 [1] CRAN (R 4.0.0)
ellipsis 0.3.0 2019-09-20 [1] CRAN (R 4.0.0)
evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.0)
fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.0)
farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.0)
fastmap 1.0.1 2019-10-08 [1] CRAN (R 4.0.0)
future 1.17.0 2020-04-18 [1] CRAN (R 4.0.0)
ggplot2 3.3.0 2020-03-05 [1] CRAN (R 4.0.0)
ggridges 0.5.2 2020-01-12 [1] CRAN (R 4.0.0)
globals 0.12.5 2019-12-07 [1] CRAN (R 4.0.0)
glue 1.4.0 2020-04-03 [1] CRAN (R 4.0.0)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.0.0)
gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.0)
gtools 3.8.2 2020-03-31 [1] CRAN (R 4.0.0)
htmltools 0.4.0 2019-10-04 [1] CRAN (R 4.0.0)
htmlwidgets 1.5.1 2019-10-08 [1] CRAN (R 4.0.0)
httpuv 1.5.2 2019-09-11 [1] CRAN (R 4.0.0)
igraph 1.2.5 2020-03-19 [1] CRAN (R 4.0.0)
inline 0.3.15 2018-05-18 [1] CRAN (R 4.0.0)
isoband 0.2.1 2020-04-12 [1] CRAN (R 4.0.0)
jsonlite 1.6.1 2020-02-02 [1] CRAN (R 4.0.0)
labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
later 1.0.0 2019-10-04 [1] CRAN (R 4.0.0)
lattice 0.20-41 2020-04-02 [1] CRAN (R 4.0.0)
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 4.0.0)
lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.0)
listenv 0.8.0 2019-12-05 [1] CRAN (R 4.0.0)
loo 2.2.0 2019-12-19 [1] CRAN (R 4.0.0)
magrittr 1.5 2014-11-22 [1] CRAN (R 4.0.0)
markdown 1.1 2019-08-07 [1] CRAN (R 4.0.0)
MASS 7.3-51.5 2019-12-20 [1] CRAN (R 4.0.0)
Matrix 1.2-18 2019-11-27 [1] CRAN (R 4.0.0)
matrixStats 0.56.0 2020-03-13 [1] CRAN (R 4.0.0)
mgcv 1.8-31 2019-11-09 [1] CRAN (R 4.0.0)
mime 0.9 2020-02-04 [1] CRAN (R 4.0.0)
miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.0.0)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.0)
mvtnorm 1.1-0 2020-02-24 [1] CRAN (R 4.0.0)
nleqslv 3.3.2 2018-05-17 [1] CRAN (R 4.0.0)
nlme 3.1-147 2020-04-13 [1] CRAN (R 4.0.0)
openssl 1.4.1 2019-07-18 [1] CRAN (R 4.0.0)
packrat 0.5.0 2018-11-14 [1] CRAN (R 4.0.0)
pillar 1.4.4 2020-05-05 [1] CRAN (R 4.0.0)
pkgbuild 1.0.7 2020-04-25 [1] CRAN (R 4.0.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.0)
pkgload 1.0.2 2018-10-29 [1] CRAN (R 4.0.0)
plogr 0.2.0 2018-03-25 [1] CRAN (R 4.0.0)
plyr 1.8.6 2020-03-03 [1] CRAN (R 4.0.0)
praise 1.0.0 2015-08-11 [1] CRAN (R 4.0.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.0)
processx 3.4.2 2020-02-09 [1] CRAN (R 4.0.0)
promises 1.1.0 2019-10-04 [1] CRAN (R 4.0.0)
ps 1.3.2 2020-02-13 [1] CRAN (R 4.0.0)
purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.0)
R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.0)
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 4.0.0)
Rcpp * 1.0.4.6 2020-04-09 [1] CRAN (R 4.0.0)
RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 4.0.0)
reshape2 1.4.4 2020-04-09 [1] CRAN (R 4.0.0)
rlang 0.4.5 2020-03-01 [1] CRAN (R 4.0.0)
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.0)
rsconnect 0.8.16 2019-12-13 [1] CRAN (R 4.0.0)
rstan 2.19.3 2020-02-11 [1] CRAN (R 4.0.0)
rstantools 2.0.0 2019-09-15 [1] CRAN (R 4.0.0)
rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.0)
scales 1.1.0 2019-11-18 [1] CRAN (R 4.0.0)
shiny 1.4.0.2 2020-03-13 [1] CRAN (R 4.0.0)
shinyjs 1.1 2020-01-13 [1] CRAN (R 4.0.0)
shinystan 2.5.0 2018-05-01 [1] CRAN (R 4.0.0)
shinythemes 1.1.2 2018-11-06 [1] CRAN (R 4.0.0)
sourcetools 0.1.7 2018-04-25 [1] CRAN (R 4.0.0)
StanHeaders 2.19.2 2020-02-11 [1] CRAN (R 4.0.0)
stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0)
stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.0)
sys 3.3 2019-08-21 [1] CRAN (R 4.0.0)
testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.0)
threejs 0.3.3 2020-01-21 [1] CRAN (R 4.0.0)
tibble 3.0.1 2020-04-20 [1] CRAN (R 4.0.0)
tidyselect 1.0.0 2020-01-27 [1] CRAN (R 4.0.0)
utf8 1.1.4 2018-05-24 [1] CRAN (R 4.0.0)
vctrs 0.2.4 2020-03-10 [1] CRAN (R 4.0.0)
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 4.0.0)
withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.0)
xfun 0.13 2020-04-13 [1] CRAN (R 4.0.0)
xtable 1.8-4 2019-04-21 [1] CRAN (R 4.0.0)
xts 0.12-0 2020-01-19 [1] CRAN (R 4.0.0)
yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
zoo 1.8-7 2020-01-10 [1] CRAN (R 4.0.0)

[1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

1 Like

Move, rename, or delete ~/.Renviron and ~/.R/Makevars and try again.
More specifically, those files should not define the paths anymore; you can still include CXX flags for optimizations.

My guess is you have macos-rtools installed and configured, but R is now configured to use Xcode. I received the same error before I modified those to exclude any paths. R4.0 should work fine on OSX with only Xcode installed, and no configuration in ~/.Renviron and ~/.R/Makevars

Thanks for the reply. I have the exact problem. But I could not change the path “~/.Renviron and ~/.R/Makevars”. Will you give some insight on how to do it? Thank you so much.

I’m getting these problems after deleting .Renviron and Makevars, as you had suggested in an earlier thread. So that doesn’t solve the problem.

1 Like

Have you all checked this thread?

Yes, I have read and worked through this thread. The parallel workaround did not work for me (Mojave). I am thinking of upgrading to Catalina and trying again.

Ah, right, I’m on Catalina… :)

Ah sorry; that’s what I get for skimming.

This sounds trivial, and I apologize - But 1) Did you restart R after changing those files and 2) What have you used miniconda for? It seems to be looking for the C++ standard library headers in /Users//miniconda/include

Contrary to my previous advice, you may need to set up a ~/.Renviron that specifies a path that searches for the Xcode c++ headers first. My guess is that miniconda changed some path variables to search for miniconda’s c++ headers first, rather than Xcode’s. Although I tested on OSX, I am primarily a linux user, so I am unsure how to change the R session’s path, or your system path, to prioritize Xcode. (I literally only ran OSX for a 10-20 hours in a VM to verify the installation procedure from a clean installation; likewise with windows 10).

Is there an OSX user here that can give either the system-method or an R session variable/expression that forces R to look for headers in the correct path?

I solved the brms problem as follows:

  1. Installed Catalina (and reset bash as my default shell)
  2. Reinstalled R and RStudio, and rstan and brms
  3. Discovered that miniconda had edited my .bash_profile file and added the offending path which was causing all the confusion. Removed it from .bash_profile.
  4. I added back an .Renviron file with the path to the C++ toolchain from Xcode:

PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1:${PATH}

Restarted R in RStudio. brms works fine now. However, I could not get 4 chains to run in rstan, despite adding this line:

cl <- parallel::makeCluster(2, setup_strategy = “sequential”)

When I run the following code, I still get an error:

library(rstan)
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)

cl <- parallel::makeCluster(2, setup_strategy = "sequential") 

schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))

fit <- stan(file = 'schools.stan', data = schools_dat)

Errors:

starting worker pid=3053 on localhost:11664 at 17:02:57.875
starting worker pid=3052 on localhost:11664 at 17:02:57.880
starting worker pid=3051 on localhost:11664 at 17:02:57.883
starting worker pid=3050 on localhost:11664 at 17:02:57.884
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Execution halted
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
Error in unserialize(node$con) : error reading from connection
Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
Execution halted
Execution halted
Error in makePSOCKcluster(names = spec, ...) : 
  Cluster setup failed. 4 of 4 workers failed to connect.
In addition: Warning message:
In readLines(file, warn = TRUE) :
  incomplete final line found on '/Users/shravanvasishth/Downloads/schools.stan'

I hope that RStudio will fix this soon, because right now I am in the middle of teaching a course in Bayesian data analysis, and stuck in hospital already for two weeks (i.e., away from my backup machines which actually run rstan etc.). It’s going to be embarrassing if I have to tell my students that, sorry, I can’t run my own rstan code right now (well, I can run it from the command line). :)

If you cant find a fix for running the cores in parallel, you could try adding cores = 1 as an argument to brm().

I can’t do that because I am working collaboratively with someone else on a book, and I can’t customize the code so it works for me alone. I would rather by-pass RStudio,

Right now I am trying to compile the bookdown book from the command line, and am getting weird pop-ups in my browser, with weird messages like:

“Click the Refresh button to see progress of the chains”

"Click the Refresh button to see progress of the chains
starting worker pid=4270 on localhost:11926 at 17:31:58.747
starting worker pid=4273 on localhost:11926 at 17:31:58.751
starting worker pid=4272 on localhost:11926 at 17:31:58.751
starting worker pid=4271 on localhost:11926 at 17:31:58.753
"
Somehow, running the book after starting R on the command line and then rendering the book is leading to this novel behavior.

Hi @vasishth

https://github.com/rstudio/rstudio/issues/6692#issuecomment-619645114

thanks,tried it, didn’t work.