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