Unable to run RStan (and brms)

If I run

example(stan_model, package = "rstan", run.dontrun = TRUE)

RStudio answers:

Building R package from source requires installation of additional build tools.
Do you want to install the additional tools now?

The question comes up twice.

Whether I click Yes or No, I end up with an error message as below:

Error in compileCode(f, code, language = language, verbose = verbose) :
In file included from :1:In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:82:In file included from /usr/local/clang6/include/c++/v1/new:91:In file included from /usr/local/clang6/include/c++/v1/exception:82:In file included from /usr/local/clang6/include/c++/v1/cstdlib:86:/usr/local/clang6/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found#include_next <stdlib.h> ^~~~~~~~~~1 error generated.make: *** [file85623a4758e7.o] Error 1

Restarting R and using VS code instead, again runnning

example(stan_model, package = "rstan", run.dontrun = TRUE)

gives the same error:

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

I see that I have more than one “stdlib.h” on disc, all from long back.
I have tried to follow several online suggestions, with no luck.

My attempt to use brms (which I want to use) originally triggered this error. But strangely, I am able to run a regression model with blavaan (which I believe calls RStan), but blavaan is currently very slow. So if I’m to stick with R, I’d like to use brms.

How do I solve this problem when running RStan and brms?

Christopher

Hi and welcome. A few things that will help:
What is your OS and version? What hardware are you running on?
I see clang in there is this a mac? If so are you on the Apple Silicon (M1, M2, etc) or some other chip?

thanks

Thank you.

iMac Pro, Intel Zeon W
OS: Ventura 13.1

I don’t have a way to test this out, given my mac hardware and software. But I will dig around here to see if this has cropped up before.

Oh do you have Xcode and Xcode command line tools installed?

It looks like you have multiple c++ toolchains installed: /usr/local/clang6 which is causing issues with the compiler finding the right files. Are you using homebrew or similar?

1 Like

I’m sorry for the late reply.
I guess I’ve given up on using Stan (but might use it later via blavaan if blavaan becomes faster).

@andrjohns I haven’t heard of homebrew before, so no, I’m not using it. I looked for clang6 and found a folder with four nested folders - which to my ignorant eyes didn’t include anything suspicious.

@Ara_Winter Yes, I do have Xcode installed. When I open Xcode (Version 14.2) on the Mac desktop, it shows me a dialogue box telling me that iOS 16.2 and macOS 13.1 have built-in versions and it allows me to install on watch0S 9.1 or tvOS 16.1. I’m not interested in that, but Xcode does not allow me to do anything other than installing; I’m not allowed to shut Xcode down. (So I had to use Force Quit).