Stan with Mojave MacOS

Hi everyone,

I recently updated my MacOS software to Mojave and since I have not been able to use Stan with R. When I try loading the ‘rstan’ package, I get the following error:

Loading required package: StanHeaders
Error in value[3L] :
Package ‘StanHeaders’ version 2.17.2 cannot be unloaded:
Error in unloadNamespace(package) : namespace ‘StanHeaders’ is imported by ‘rstan’ so cannot be unloaded

I have tried to look at re-installing RStan, but when I execute

pkgbuild::has_build_tools(debug = TRUE)

I return FALSE, so I think it might be something wrong with my C++ toolchain. I followed some pages to, which states that the macOS R toolchain installer isn’t ready for Mojave yet. Does this mean I’m going to just have to wait til the installer is out?

I’m not really sure what this necessarily means, so any help would be much appreciated!

Thank you


A friend of mine solved this issue using the console with the following lines

xcode-select --install

cd /Library/Developer/CommandLineTools/Packages

open .

Then, you should be able to install toolchain.


1 Like

Thanks Lucas, it works now!

Hi all! Any suggestions to help would be appreciated. Ive tried the suggestion listed above but I am still not able to install rStan on Mojave. I get this error:

In file included from chains.cpp:19:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/prim/arr/err/check_nonzero_size.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/prim/scal/err/invalid_argument.hpp:4:
In file included from /usr/local/clang4/bin/…/include/c++/v1/typeinfo:61:
In file included from /usr/local/clang4/bin/…/include/c++/v1/exception:82:
In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:
/usr/local/clang4/bin/…/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found
#include_next <stdlib.h>
1 error generated.
make: *** [chains.o] Error 1
ERROR: compilation failed for package ‘rstan’
─ removing ‘/private/var/folders/f4/klkzrkr50f98f30tr60y_qc80000gp/T/RtmpaViYT7/Rinst8946c8dab5e/rstan’
ERROR: package installation failed
Error in processx::run(bin, args = real_cmdargs, stdout_line_callback = real_callback(stdout), :
System command error

We need to see more of the error message, particularly the part with the string error:.

Hello. I have updated to show the full error