Brms/rstan on R 4.0

Continuing the discussion from Dealing with R 4.0:

Despite the fixes listed, all of which I’ve tried, I continue to get the following error message when attempting to run brms:

Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! In file included from :1: In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13: 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 /usr/local/clang7/include/c++/v1/new:91: In file included from /usr/local/clang7/include/c++/v1/exception:82: In file included from /usr/local/clang7/include/c++/v1/cstdlib:86: /usr/local/clang7/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found #include_next <stdlib.h> ^~~~~~~~~~ 1 error generated. make: *** [file366d7c9e81e3.o] Error 1

Error in sink(type = “output”) : invalid connection

I’m running R 4.0.1 on a Macbook Pro, latest versions of all packages/programs (eg, Catalina 10.15.5). I’ve uninstalled and reinstalled rstan dozens of times to no avail. I’ve deleted the /usr/local/clang code as well as the Makevar files. I have Xcode running.

So, my questions are:

  1. why can’t I run this simple code using brms (fit1 <-
    brm(data = d,
    family = gaussian,
    weight ~ 1 + height,
    prior = c(prior(normal(0, 100), class = Intercept),
    prior(normal(0, 100), class = b),
    prior(cauchy(0, 10), class = sigma)),
    chains = 4, cores = 2, iter = 2000, warmup = 1000,
    seed = 2)
  2. does rstan (or other packages, eg, XQuartz) have to be running in background?
  3. there are numerous ways to install rstan - which is optimal?

If code needs to be added somewhere, please specify exactly where it goes.

Many thanks!

Hi,

This,

indicates that there is still something pointing at an old clang installation…

  1. Remove all things concerning R: rm ~/.Renviron ~/.Rprofile ~/.R/Makevars
  2. Check that you haven’t set any paths anywhere by typing env in the terminal (read carefully and see that you don’t have anything with clang there).
  3. Uninstall old clang stuff by carefully following these instructions.

Restart the computer (just in case…)

2 Likes

torkar - thank you so much!! the program started to run and got farther than ever BUT I still got the following error (indecipherable to me, I’m just an epidemiologist):

Compiling the C++ model
Start sampling
starting worker pid=923 on localhost:11179 at 11:38:39.248
starting worker pid=924 on localhost:11179 at 11:38:39.249
Error in unserialize(node$con) : error reading from connection
Calls: -> slaveLoop -> makeSOCKmaster
Execution halted
Error in unserialize(node$con) : error reading from connection
Calls: -> slaveLoop -> makeSOCKmaster
Execution halted
Error in makePSOCKcluster(names = spec, …) :
Cluster setup failed. 2 of 2 workers failed to connect.

Any ideas about this?
Many thanks!!

Add this to your ~/.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")
}%                                                                       

Hi again.
Got the same or very similar message:

Compiling the C++ model
recompiling to avoid crashing R session
Start sampling
starting worker pid=1260 on localhost:11179 at 11:56:16.639
starting worker pid=1261 on localhost:11179 at 11:56:16.639
Error in unserialize(node$con) : error reading from connection
Calls: → slaveLoop → makeSOCKmaster
Execution halted
Error in unserialize(node$con) : error reading from connection
Calls: → slaveLoop → makeSOCKmaster
Execution halted
Error in makePSOCKcluster(names = spec, …) :
Cluster setup failed. 2 of 2 workers failed to connect.

Sorry to keep bothering you with this but I really want to be able to use brms…

Many thanks.

Hi

Did you put that in a file called .Rprofile in your home directory (i.e., not in the directory .R/)? In short,

echo '## 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" && RSTUDIO_TERM")) &&
    Sys.info()["sysname"] == "Darwin") {
  parallel:::setDefaultClusterOptions(setup_strategy = "sequential")
}' > ~/.Rprofile

Did you restart RStudio?

Hi.
Excuse my ignorance, but should I put the file as above (starting with echo) or the shorter one starting with if? I ran the first one and got the same message…I’ll try the second one above, starting with echo…
thanks

Okay, the file starting with ‘echo’ didn’t work either, same error message. I restarted RStudio every time.
Thanks.

Hi

cut and paste this,

echo '## 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" && RSTUDIO_TERM")) &&
    Sys.info()["sysname"] == "Darwin") {
  parallel:::setDefaultClusterOptions(setup_strategy = "sequential")
}' > ~/.Rprofile

in your terminal and press enter. Then restart RStudio, if that doesn’t work then … hmm… I think we’ll call on @bgoodri to perhaps give us some help :)

Gee, this is really fun!!
I cut and pasted but probably shouldn’t have done something: I put it in the Terminal in RStudio, which is why I probably got this error message:
Compiling the C++ model
Start sampling
Error: 3:49: unexpected string constant
3: if (Sys.getenv(“RSTUDIO”) == “1” && RSTUDIO_TERM")) &&
4: Sys.info()["
^
Execution halted
Error: 3:49: unexpected string constant
3: if (Sys.getenv(“RSTUDIO”) == “1” && RSTUDIO_TERM")) &&
4: Sys.info()["
^
Execution halted

Should I have put it in the /.Rprofile file instead? I actually did put it there as well…if that was an error, please advise. I’m use to diseased people, not my diseased ignorance of the intricacies of coding.

Thanks.

Sorry, forgot the last two lines of error message:
Error in makePSOCKcluster(names = spec, …) :
Cluster setup failed. 2 of 2 workers failed to connect.

Exactly this should be in ~/.Rprofile

if (Sys.getenv("RSTUDIO") == "1" && RSTUDIO_TERM")) &&
    Sys.info()["sysname"] == "Darwin") {
  parallel:::setDefaultClusterOptions(setup_strategy = "sequential")
}

Then restart RStudio. If it doesn’t work we’ll need to wait for Ben to come save us :)

okay. if it doesn’t matter that I entered that code into Terminal on RStudio (as well as in the home directory), then we need the help of Prof Ben.
I really appreciate your help - we got rid of the clang garbage and other things, so that’s progress. Your patience is greatly respected and admired.
Thanks.

You should enter it in Terminal on OSX not in RStudio.

If you open Terminal in OS X and type,

cat ~/.Rprofile

What does it say?

no such file or directory…

I also get system error messages when I try to enter the code…
Williams-MacBook-Pro:~ williamholden$ if (Sys.getenv(“RSTUDIO”) == “1” && RSTUDIO_TERM")) &&
-bash: syntax error near unexpected token "RSTUDIO"' Williams-MacBook-Pro:~ williamholden$ Sys.info()["sysname"] == "Darwin") { -bash: syntax error near unexpected token [“sysname”]’
Williams-MacBook-Pro:~ williamholden$ parallel:::setDefaultClusterOptions(setup_strategy = “sequential”)
-bash: syntax error near unexpected token `setup_strategy’

But I do have the code in file in home directory:
1D65D0EC-DFF5-4B83-8B91-56CEABC8A102_4_5005_c

Wrong. You added everything. Add only what I showed you the first time:

if (Sys.getenv("RSTUDIO") == "1" && RSTUDIO_TERM")) &&
    Sys.info()["sysname"] == "Darwin") {
  parallel:::setDefaultClusterOptions(setup_strategy = "sequential")
}

The above, and only the above, should be in ~/.Rprofile`.

Okay, I edited the file and reran but still got the same message:
Compiling the C++ model
Start sampling
Error: 3:49: unexpected string constant
3: if (Sys.getenv(“RSTUDIO”) == “1” && RSTUDIO_TERM")) &&
4: Sys.info()["
^
Execution halted
Error: 3:49: unexpected string constant
3: if (Sys.getenv(“RSTUDIO”) == “1” && RSTUDIO_TERM")) &&
4: Sys.info()["
^
Execution halted

Do I have to ‘clean it up’ from the RStudio terminal? Not sure how to do that…