Dealing with Catalina II

Thanks for the reply @torkar

I now used a mac just restored to factory settings and updated to Catalina.

Installed R 3.6.2
Installed R studio 1.2.5033
Installed Xcode 11.3, licence accepted
Installed macos.-rtools 3.2.2

Modified .R/Makevars using the terminal as you just suggested me…

Installed rstan from source…

But I still get the same error:
[1] “Error in sampler$call_sampler(args_list[[i]]) : " " c++ exception (unknown reason)”
error occurred during calling the sampler; sampling not done

What am I doing differently?

Did you install Xcode command line tools?

1 Like

yes I did. the macos-rtools does it…
I tried anyway to install them from the terminal afterwards and it says it’s installed already…

I have the exact same software that you have and it works for me. Could you post a minimum working example here so I can try it out?

I removed everything again and then reinstalled manually the Command Line Tools, clang7 and gfortran6.1(without using the macos-rtools)… and now models are sampling fine!

Thanks again for all the support you gave me!



Managed to stumble across R’s build settings for CRAN official binaries here:

Relevant file is:

The bug is related to clang4 complier being hard coded inside the fixpathR script.


find . -name \*.dylib -or -name \*.so| xargs -n 1 install_name_tool -change /usr/local/clang4/lib/$gcclib $R/lib/$gcclib


install_name_tool -change /usr/local/clang4/lib/$gcclib $R/lib/$gcclib $rbin

I’ve flagged it for Simon and should hear back soon ™.

Hi I’m on Catalina and recently I installed the rstan on my rstudio but it doesn’t work with the following error though I also installed the Xcode according to its recommendation to run the package.
Error in sink(type = “output”) :
: Warning message:
In system(cmd, intern = !verbose) :
‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file248670b432b1.cpp 2> file248670b432b1.cpp.err.txt’
Error in map2stan(alist(y ~ dnorm(mu, sigma), mu ~ dnorm(0, 14.14), sigma ~ :
Something went wrong, when calling Stan. Check any debug messages for clues, detective.
the code I run is the following:
Can anyone help me to figure it out?

FYI - I have found this issues can be solved (at least on the systems I have access to - YMMV) WITHOUT modifying the Makevars file or installing mac-rtools by re-installing the dependencies in order (i.e. one at a time, not all at once):

  • Rcpp
  • StanHeaders
  • rstan

As a general rule, editing the Makevars should be a last resort - it can potentially affect every compiled R package on the system. You can end up with some difficult to diagnose bugs in other packages.

1 Like

Not to add to the fun, but having a different but related problem. Upgraded to Catalina, followed all @coatless steps (thanks for those!). Rcpp::sourceCpp(“helloworld.cpp”) example works fine. rstan and rstanarm both work fine (sampling etc). The test program works fine. But, once I run library(rstan), while I can compile and run stan models, I can no longer compile any other c++ files. e.g this fails, with a bunch of messages about " #pragma clang diagnostic pop"


Rcpp::sourceCpp(code = 
#include <RcppArmadillo.h>

// [[Rcpp::depends(RcppArmadillo)]]

// [[Rcpp::export]]
void hello_world() {
  Rcpp::Rcout << "Hello World!" << std::endl;

/*** R



But, if I restart R, and comment out #library(rstan) everything works fine. Same problem for cpp files that don’t use RcppArmadillo, or for compiling models with Template Model Builder… Not sure if this counts as a stan problem, but since the behavior only starts after loading stan figured I’d start here. The above example does work if I load ggplot2 first, in reference to the issues noted in the results of test program; it’s only loading rstan that seems to cause the issues. Same problem on a colleagues Mac that I didn’t set up, so doesn’t seem likely to be a result of esoteric setup on my end?

1 Like

Those are only warning messages. We need the actual error message, which should be on a line that includes error: (with the colon).

I believe these are the three that keep repeating throughout the messages, thanks!

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/eigen_plugins.h:22:30: error: no template named 'conditional_t' in namespace 'std'; did you mean 'conditional'?
using double_return_t = std::conditional_t<std::is_const<std::remove_reference_t<T>>::value,
/usr/local/clang7/include/c++/v1/type_traits:424:33: note: 'conditional' declared here
    struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;};

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/eigen_plugins.h:22:63: error: no template named 'remove_reference_t' in namespace 'std'; did you mean 'remove_reference'?
using double_return_t = std::conditional_t<std::is_const<std::remove_reference_t<T>>::value,
/usr/local/clang7/include/c++/v1/type_traits:1110:50: note: 'remove_reference' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference        {typedef _Tp type;};

/Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/prim/mat/eigen_plugins.h:60:10: error: no template named 'enable_if_t' in namespace 'std'; did you mean 'enable_if'?
    std::enable_if_t<std::is_pointer<T>::value, reverse_return_t<T>>
/usr/local/clang7/include/c++/v1/type_traits:435:63: note: 'enable_if' declared here
template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};

Yes, that is it. What is packageVersion("StanHeaders")?

StanHeaders version ‘’

Does it work if you call in R


after calling library(rstan) but before calling sourceCpp?


Yes, that fixes it!

OK. I guess just go that way for now. We had to set that environmental variable to move StanHeaders forward on CRAN but can remove it in the future.

Good to know, many thanks

Hi Everyone!

I used the latest installer linked above, but that left me with a non-working setup for running stan models. The reasons seems to be that the tools leave you with a ~/.R/Makevars with this content:

# 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
# clang: end

but for Stan we have to also modify the C++14 flags like this:

# 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

CXX14FLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPF14LAGS=-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

With the above changes for C++14 everything works now for me.

Tagging @mcol

… and for everyone who is blocked by Catalina not being allowed to install the .pkg file… a simple CTRL+right click on the file, then clicking “Open” will get the installer going (for me).

Did you want to tag somebody else? I’m not on Mac.

1 Like

ups… sorry… I meant @coatless