Problem when running brm function on Mac Catalina

Hi everyone,

I’m new to brms package while I have used R for some years. After installation of the brms package by following the instructions in the link, I cannot run through the example code in the help file of the brm().

The error message is:
Compiling the C++ model
Trying to compile a simple C file
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Error in file(con, “r”) : cannot open the connection
Calls: -> .shlib_internal -> checkCXX -> readLines -> file
In addition: Warning messages:
1: In file(con, “r”) :
‘raw = FALSE’ but ‘/Users/yaoxin/.R/Makevars’ is not a regular file
2: In file(con, “r”) :
cannot open file ‘/Users/yaoxin/.R/Makevars’: it is a directory
Execution halted
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file273c09ece.cpp 2> file273c09ece.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection
rror in compileCode(f, code, language = language, verbose = verbose) :

The example code I used that from the help file of the brm() is:
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)

I checked following things after checking some latest and hot topic in this website, which are:

  1. I have uninstalled old version of clang by following messages in this link Brms/rstan on R 4.0
  2. I also checked situations that posted in this topic Issue compiling Stan on R 4.0 / Catalina and this topic Problem running Rstan 2.19.3 in R version 4.0.1
  3. I have installed the Xcode with the latest version, clang 8 and commandlinetools. The Mac system of my computer also is on the latest version.
  4. Now, the folder /Users/yaoxin/.R/Makevars is empty.

My operating system: macOS Catalina version 10.15.5
brms version I used: 2.13.0
R version I used: 4.0.1

Thank you very much if anyone could give some helpful suggestions about my problem.

Welcome to the community!

.R/Makevars is a file, not a directory. Remove the directory, and I believe that the file is not really needed, but you can put compiler flags there if needed, i.e., CXX14FLAGS=-O3 -mtune=native -march=native -w

In ~/.Rprofile (notice that it’s placed directly in your home directory) you can put this to avoid a bug in RStudio if you use that:

## 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")) &&["sysname"] == "Darwin" ) {
  parallel:::setDefaultClusterOptions(setup_strategy = "sequential")


Thank your! And thank you a lot for your help! My problem was fixed by following your suggestions. And now I can run through the example code in the help file of function brm. That’s wonderful! Hope other people who has similar problem can also get help from your suggestion here.

Thanks very much again!