As of January 1, 2020, the Catalina version of the Mac OSX operating system prevents the recommended C++ toolchain installer by @coatless from running. If you try, you will see something like
The RStan installation instructions here need to be updated.
It is currently possible on a mac with catalina to run install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE), have it not ask you to compile from source, and have pkgbuild::has_build_tools(debug = TRUE) return TRUE and still have rstan compilation problems.
I now know this because of a group of undergraduates chasing me with pitchforks.
Is the correct advice for all cases to do the manual install guide above and install from source?
Yes. Unfortunately, the pkgbuild::has_build_tools function tests whether it can compile a hello world program in C, which Catalina with Xcode can do. However, Catalina with Xcode miscompiles C++ so as to mispropagate exceptions under R, so most non-trivial Stan programs will terminate the MCMC without returning results. That is why we use LLVM clang++ rather than Xcode clang++ until Apple started blocking our toolchain installer starting January 1 because it is not a certified Apple Developer application.
If the people would put down their pitchforks and read the wiki, it does eventually say
If this line ultimately returns TRUE , then your C++ toolchain is properly installed and you can jump to the next section, unless you have the Catalina version of the Mac OSX operating system (see 3 below).
…
3 If you use a Mac, a link will appear but do not click on it. Instead go here
which takes you to a page that says
We recommend using the macOS R toolchain installer for pre-Catalina versions of the operating system. If you have Catalina, then you need to follow these instructions starting from “Manual Install Guide” to download and configure your C++ toolchain.
Suggestions are more than welcome as to how to reword that or anyone can just edit the wiki pages themselves. But I don’t know how better to explain in a few words why the only way forward at the moment is so messed up on Macs.
I installed rstan on Catalina today following all previous instructions. Everything works perfectly fine and straightforward if I simply ignore the extra Makevars component in the “Manual Install Guide”:
Note: If you are on macOS Mojave (10.14) or higher, you will need to add into ~/.R/Makevars a set of compilation flags.
mkdir -p ~/.R
# Fill with appropriate flag statements
cat <<- EOF > ~/.R/Makevars
# clang: start
CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include
SHLIB_CXXLDFLAGS+=-Wl,-rpath,\${R_HOME}/lib \${R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,\${R_HOME}/lib \${R_HOME}/lib/libc++abi.1.dylib
# clang: end
EOF
I’m trying to install Rstan on a new Mac with Catalina. I tried following the directions on Github, which were a departure from previous installations that specifically referenced Xtools.
I confess that after following multiple links from the above messages, opening the Terminal and trying to supply recommended commands … I’m not still not able to run a Stan model.
By chance, is there a step-by-step Catalina instruction guide in the works?
Catalina (mis)behaves different ways for different people. But the procedure is basically to install the toolchain by circumventing the security measures with a Ctrl-click to open it. And then see what, if anything, goes wrong. Sometimes it involves a
xcode-select --install
in the Terminal app or the Terminal tab of RStudio. Sometimes something else.
And yet the models estimate if I dismiss the prompt. Dismissing the prompt will be a minor nuisance when it’s time to estimate a model, but at least I’m back in business.
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Dense:1:
/Library/Frameworks/R.framework/Versions/3.6/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
#include <complex>
^~~~~~~~~
3 errors generated.
make: *** [foo.o] Error 1
[1] FALSE