Dealing with Catalina

OK. It is known to be possible to avoid the mishandled exceptions if you avoid all of R’s clang stuff, but that is not a general enough workaround for us (or Rcpp / inline). In principle, everyone could just use Xcode but you lose out on the ability to use OpenMP and all the R packages compiled on CRAN that have Stan programs are still broken.

From reading @nicokist’s output, he’s using the homebrew compiler…

So, moving totally away from R’s official binary works… Maybe this should be escalated over to Simon (macOS CRAN maintainer)

If I had a Mac, I would. But I am not much use when I have to borrow someone else’s machine (that has Catalina) to respond to posts with test cases.

I can say that

Rcpp::sourceCpp(code = 
#include <Rcpp.h>
using namespace Rcpp; 

// [[Rcpp::export]]
int throw_exception() { 
  std::stringstream errmsg; errmsg << "this is an exception";
  throw std::domain_error(errmsg.str()); 
  return 0;


works correctly (i.e. says “this is an exception”) if

  • One uses clang++ on Linux
  • One uses homebrew’s R on a Mac with Catalina
  • One uses Xcode’s clang++ on a Mac with Catalina, provided no other C++ packages from CRAN have previously been loaded

And the problem has not much to do with Stan, except that we call Rcpp::sourceCpp and inline::cxxfunction and throw exceptions at runtime. But even packages like rstanarm wiith Stan programs that are compiled in advance on CRAN are affected.

Any updates?

Still broken

If you are using Catalina with the recommended clang++ installer, try the advice in


Worked a treat - thank you! :)

Thank you for that! I have installed them a while ago, so I just ran the code you provided. However, after running it, my stan file could check its gramma once before it didn’t work again. Is there anything I’m not doing correctly? Thanks!

You may have to reinstall it from source at the moment with

install.packages("rstan", type = "source")

Does this mean we will have another break when R3.7 moves to clang 8?

Wouldn’t surprise me but my guess is that when clang8 is introduced, @coatless will update the Mac installer to use it and it will set SHLIB_CXXFLAGS to link against whatever libc++.1.dylib comes with R, which one would expect CRAN to have compiled with clang8.

I’m actually more worried about Windows for R 3.7.

Thanks so much!

Next version of R will be 4.0.0 to account for the compile toolchain switch, c.f.


Have you begun testing with RTools 4.0? Jeroen Ooms made it available:

Yes, I have been encouraging people to test rstan on it

for a while, but AFAIK I am the only one who has. It works (except LTO) for me, but it is a huge change.

I just tried this (after uninstalling RStan and using @coatless new installer) and got:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun ERROR: compilation failed for package ‘rstan’

So it appears that I am unable to actually compile Stan. Have you seen this error anywhere else since the Catalina roll out?

Try first doing xcode-select --install from the Terminal app or the Terminal tab of RStudio.

So, the installer attempts to install the Xcode CLI tools for you. In the process, we trigger:

sudo xcode-select --reset

And then

sudo xcode-select --install

The reset should fix the xcrun error, From there, the installation should be fine.

What macOS are you on? Mojave or Catalina?

I’m running Catalina (unfortunately). running xcode-select --install seems to have fixed the xcrun error (at least it did for installing cmdstanr which failed with a similar error initially). Unfortunately, I’m still waiting for that to finish compiling and haven’t been able to try install.packages(“rstan”, type = “source”) yet. As soon as cmdstanr is finished, I’ll give that a shot and post an update.

@mattwilliamson13 if CmdStanR still gives you trouble maybe @ssp3nc3r can help. I know he (and others) have been able to get it running on Catalina.

Thanks @Jonah. Do you have any sense for how long CmdStanR should take to compile during the install on a 2015 MacBook Pro with moderate specs? Are we talking minutes? Hours? To clarify, I mean the install_cmdstan() install and compile of Stan

I can’t really tell if I’m making progress