Dealing with Catalina II

Hello everyone,
I am still not able to have rstan working properly.

I now freshly installed R, Rstudio and installed the macos-rtools [v3.2.2] without having XCode installed on the mac, but I am still having the same issue as before.

Do you have any new suggestion?

Thanks

I also just tried to freshly install everything having XCode already installed…
And I modified Makevars as you suggested, but I’m still getting

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

Hi @Save,

  1. Install Xcode. Make sure to install the command line tools and accept the license.
  2. Install macos-rtools. Follow these instructions.
    I use this in my .R/Makevars:
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,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
SHLIB_CXX11LDFLAGS+=-Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib
  1. Recompile rstan from source:
    install.packages("rstan", type = "source")

The above worked for me :)

3 Likes

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!

2 Likes

@bgoodri

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

https://svn.r-project.org/R-dev-web/trunk/QA/Simon/R-build

Relevant file is:
https://svn.r-project.org/R-dev-web/trunk/QA/Simon/R-build/fixpathR

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

Instances:

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

and

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:
require(rstan)
require(rethinking)
y<-rnorm(1e2,mean=0,sd=1)
m8.5b<-map2stan(
alist(
y~dnorm(mu,sigma),
mu~dnorm(0,14.14),
sigma~dcauchy(0,1)
),
data=list(y=y),
start=list(mu=0,sigma=1),
chains=2,iter=4e3,
warmup=1e3
)
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"

library(rstan)

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

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

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

/*** R
hello_world()
*/

'
)

hello_world()

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,
                        ~~~~~^~~~~~~~~~~~~
                             conditional
/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,
                                                         ~~~~~^~~~~~~~~~~~~~~~~~
                                                              remove_reference
/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>>
    ~~~~~^~~~~~~~~~~
         enable_if
/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 ‘2.21.0.1’

Does it work if you call in R

Sys.unsetenv("PKG_CXXFLAGS")

after calling library(rstan) but before calling sourceCpp?

1 Like

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