Rstan crashes on mac os x (Big Sur)

First Brms would not compile the models and Rstudio crashed after compiling without any further notice. I tried the same in native R from terminal and the exact same happened. Next, I removed and reinstalled Rstan but it still didnt work. I removed the Makevars file (which was set up to use llvm in order for openMp support. Stil getting errors, but not crashes. Now, again tried to reinstall Rstan from source and I get the following error (posted below)-

Any idea where I go from here?

install.packages(“rstan”, type = “source”)
trying URL ‘https://cran.rstudio.com/src/contrib/rstan_2.21.2.tar.gz
Content type ‘application/x-gzip’ length 1152008 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

  • installing source package ‘rstan’ …
    ** package ‘rstan’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs
    clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DBOOST_NO_AUTO_PTR -D_REENTRANT -DSTAN_THREADS -I’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include’ -I’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include’ -I’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include’ -I’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include’ -I’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/include’ -I/usr/local/include -fPIC -Wall -g -O2 -c Module.cpp -o Module.o
    In file included from Module.cpp:1:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp.h:27:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/RcppCommon.h:29:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:321:9: error: no member named ‘signbit’ in the global namespace
    using ::signbit;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:322:9: error: no member named ‘fpclassify’ in the global namespace
    using ::fpclassify;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:323:9: error: no member named ‘isfinite’ in the global namespace; did you mean ‘finite’?
    using ::isfinite;
    ~~^
    /usr/local/include/math.h:752:12: note: ‘finite’ declared here
    extern int finite(double)
    ^
    In file included from Module.cpp:1:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp.h:27:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/RcppCommon.h:29:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:324:9: error: no member named ‘isinf’ in the global namespace
    using ::isinf;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:325:9: error: no member named ‘isnan’ in the global namespace
    using ::isnan;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:326:9: error: no member named ‘isnormal’ in the global namespace
    using ::isnormal;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:327:9: error: no member named ‘isgreater’ in the global namespace
    using ::isgreater;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:328:9: error: no member named ‘isgreaterequal’ in the global namespace
    using ::isgreaterequal;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:329:9: error: no member named ‘isless’ in the global namespace
    using ::isless;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:330:9: error: no member named ‘islessequal’ in the global namespace
    using ::islessequal;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:331:9: error: no member named ‘islessgreater’ in the global namespace
    using ::islessgreater;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:332:9: error: no member named ‘isunordered’ in the global namespace
    using ::isunordered;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:333:9: error: no member named ‘isunordered’ in the global namespace
    using ::isunordered;
    ~~^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:339:9: error: no member named ‘abs’ in the global namespace; did you mean ‘fabs’?
    using ::abs;
    ~~^
    /usr/local/include/math.h:417:15: note: ‘fabs’ declared here
    extern double fabs(double);
    ^
    In file included from Module.cpp:1:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp.h:27:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/RcppCommon.h:29:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
    In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:644:26: error: no template named ‘numeric_limits’
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
    ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:644:60: error: no template named ‘numeric_limits’
    bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
    ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:645:18: error: no template named ‘numeric_limits’
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
    ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:645:50: error: no template named ‘numeric_limits’
    int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
    ^
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:650:17: error: no template named ‘numeric_limits’
    static_assert(numeric_limits<_FloatT>::radix == 2, “FloatT has incorrect radix”);
    ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    make: *** [Module.o] Error 1
    ERROR: compilation failed for package ‘rstan’
  • removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in
‘/private/var/folders/cq/1m6nc8p514n273gx7x1zl_rc0000gn/T/RtmplRoCTh/downloaded_packages’

sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

1 Like

I think @andrjohns knows the most about installation problems on Mac, so hopefully he has the time to look into this. In the meantime, can you try using either a newer version of rstan via Repository for distributing (some) stan-dev R packages | r-packages or use cmdstanr (Getting started with CmdStanR • cmdstanr) - brms can be configured to use cmdstanr via options(brms.backend="cmdstanr").

Hope you can get this resolved quickly

1 Like

You could also try looking at the answers for this stackoverflow question which I think is about the same problem.

Unfortunately, I could not make it work again and resorted to wiping everything related to R from the hard drive and reinstalling. Now it works again. But I´m now very skeptical about trying to reinstall with openMP support on my Mac.

1 Like

This error comes up when OSX has installed a couple of different toolchains, and this messes up the order of directories it looks for headers in.

While I haven’t tried it personally, this issue seems to have fixed for several people using the instructions in this SO comment: macos - Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace - Stack Overflow (Which @jeffreypullin also linked above)

1 Like