Stan stopped working

Hi, my version of rstan stopped working and I’m not savvy enough on the back end to understand why. When I try and run any model, I get the error code that shows up below. For reference, here is the last stan code I was trying to run, but I don’t think that’s really the issue as it’s pretty simple. R prompts me to install build tools, and then returns this long error. I’ve tried installing new command line tools for xcode (I’m running macOS big sur 11.23), reinstalling stan, updating r (now running 4.05), reinstalling stan headers, all to no avail. Please let me know if you know what to do!

data {
int<lower=0> N;
vector[N] y;
}
parameters {
real alpha;
real beta;
real<lower=0> sigma;
}
model{
alpha ~ uniform(0,1);
beta ~ uniform(0,1);
for (n in 2:N)
y[n] ~ normal(alpha + beta * y[n-1], sigma);
}

sh: clang++ -mmacosx-version-min=10.13: command not found
error in running commandcannot remove file ‘/var/folders/jn/_1k1j5mn7dv578fhbd_99yf80000gn/T//RtmpsacZ1a/filecefda863c31.stan’, reason ‘No such file or directory’make cmd is
make -f ‘/Library/Frameworks/R.framework/Resources/etc/Makeconf’ -f ‘/Library/Frameworks/R.framework/Resources/share/make/shlib.mk’ -f ‘~/.R/Makevars’ CXX=’(CXX14) (CXX14STD)’ CXXFLAGS=’(CXX14FLAGS)' CXXPICFLAGS='(CXX14PICFLAGS)’ SHLIB_LDFLAGS=’(SHLIB_CXX14LDFLAGS)' SHLIB_LD='(SHLIB_CXX14LD)’ SHLIB=‘filecefd3250e221.so’ OBJECTS=‘filecefd3250e221.o’

make would use
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/unsupported" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp’ -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/usr/local/include -fPIC -Wall -g -O2 -O3 -mtune=native -arch x86_64 -ftemplate-depth-256 -c filecefd3250e221.cpp -o filecefd3250e221.o
if test “zfilecefd3250e221.o” != “z”; then
echo clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/usr/local/lib -o filecefd3250e221.so filecefd3250e221.o /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan/lib//libStanServices.a -L’/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/lib/’ -lStanHeaders -L’/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppParallel/lib/’ -ltbb -ltbbmalloc -ltbbmalloc_proxy -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation;
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/usr/local/lib -o filecefd3250e221.so filecefd3250e221.o /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan/lib//libStanServices.a -L’/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/lib/’ -lStanHeaders -L’/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppParallel/lib/’ -ltbb -ltbbmalloc -ltbbmalloc_proxy -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation;
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
In file included from :1:In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:82:In file included from /usr/local/clang7/include/c++/v1/new:91:In file included from /usr/local/clang7/include/c++/v1/exception:82:In file included from /usr/local/clang7/include/c++/v1/cstdlib:86:/usr/local/clang7/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found#include_next <stdlib.h> ^~~~~~~~~~1 error generated.make: *** [filecefd3250e221.o] Error 1
Error in sink(type = “output”) : invalid connection

It looks like it’s not a problem with the model, maybe it’s not finding the model file (but I don’t use rstan and don’t know what your R code and file system look like).

Do you get the same error if you try to run the example bernoulli.stan model (by loading the .stan file, not including it inside the R code)?

Yeah, it won’t let me load rstan at this point, I tried to reinstall it and am now getting errors when I do so. I poked around and tried the github install with

install.packages("remotes") remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")

which after a little bit asks if I want to install build tools and then results in the following error:

Error: Failed to install ‘rstan’ from GitHub:
Could not find tools necessary to compile a package
Call pkgbuild::check_build_tools(debug = TRUE) to diagnose the problem.

Using install.packages(“rstan”) gives a similar result:

1 error generated.
make: *** [Module.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

What happens if you restart R (making sure rstan doesn’t get loaded) and run:

pkgbuild::check_build_tools(debug = TRUE)

It prompts me to install build tools and then gives me the following error:

pkgbuild::check_build_tools(debug = TRUE)
Error: Could not find tools necessary to compile a package
Call pkgbuild::check_build_tools(debug = TRUE) to diagnose the problem.

Can you try opening a terminal and running:

xcode-select --install

yep running that gives me

xcode-select: error: command line tools are already installed, use “Software Update” to install updates

i tried to update my command line tools by downloading through apple’s website but that didn’t seem to help

@torkar any chance you’ve seen something like this before?

Very fishy. I’d try to remove the command line tools,

rm -rf /Library/Developer/CommandLineTools

and then,

xcode-select --install
1 Like

I removed command line tools from terminal like you suggested, and then ran the code to reinstall them from terminal. I then restarted R and ran

pkgbuild::check_build_tools(debug = TRUE)

and got the same error as before

Error: Could not find tools necessary to compile a package
Call pkgbuild::check_build_tools(debug = TRUE) to diagnose the problem.

Super strange… and install rstan from cran still fails?

If you’re not able to get this sorted, it might also be a good idea to open an issue over on the pkgbuild github: GitHub - r-lib/pkgbuild: Find tools needed to build R packages

If I install from cran it seems to work better initally but then I get the original error I posted at the beginning of the thread when I try to run a model in stan

thank you I’ll try opening an issue there too

This is very strange,