# Stan stopped working

**URL:** <https://discourse.mc-stan.org/t/stan-stopped-working/21880>\
**Category:** RStan\
**Tags:** rstan\
**Created:** [April 14, 2021, 1:03pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880 "2021-04-14T13:03:30Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![waterbottles](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@waterbottles](https://discourse.mc-stan.org/u/waterbottles)\
**Post date:** [April 14, 2021, 1:03pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/1 "2021-04-14T13:03:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![caesoma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/caesoma/32/19767_2.png) [@caesoma](https://discourse.mc-stan.org/u/caesoma)\
**Post date:** [April 18, 2021, 3:39pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/2 "2021-04-18T15:39:43Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![waterbottles](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@waterbottles](https://discourse.mc-stan.org/u/waterbottles)\
**Post date:** [April 19, 2021, 1:30am UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/3 "2021-04-19T01:30:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [April 19, 2021, 4:18am UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/4 "2021-04-19T04:18:12Z")

</div>

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

```r
pkgbuild::check_build_tools(debug = TRUE)

```

---

<div class="post-metadata">

**Author:** ![waterbottles](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@waterbottles](https://discourse.mc-stan.org/u/waterbottles)\
**Post date:** [April 19, 2021, 12:55pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/5 "2021-04-19T12:55:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [April 19, 2021, 1:05pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/6 "2021-04-19T13:05:47Z")

</div>

Can you try opening a terminal and running:

```
xcode-select --install

```

---

<div class="post-metadata">

**Author:** ![waterbottles](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@waterbottles](https://discourse.mc-stan.org/u/waterbottles)\
**Post date:** [April 19, 2021, 1:07pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/7 "2021-04-19T13:07:47Z")

</div>

> [@andrjohns](#):
>
> `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

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [April 19, 2021, 1:11pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/8 "2021-04-19T13:11:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [April 19, 2021, 1:19pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/9 "2021-04-19T13:19:03Z")

</div>

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

```
rm -rf /Library/Developer/CommandLineTools

```

and then,

```
xcode-select --install

```

---

<div class="post-metadata">

**Author:** ![waterbottles](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@waterbottles](https://discourse.mc-stan.org/u/waterbottles)\
**Post date:** [April 19, 2021, 1:31pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/10 "2021-04-19T13:31:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [April 19, 2021, 1:41pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/11 "2021-04-19T13:41:59Z")

</div>

Super strange… and install rstan from cran still fails?

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [April 19, 2021, 2:40pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/12 "2021-04-19T14:40:39Z")

</div>

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](https://github.com/r-lib/pkgbuild)

---

<div class="post-metadata">

**Author:** ![waterbottles](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@waterbottles](https://discourse.mc-stan.org/u/waterbottles)\
**Post date:** [April 19, 2021, 2:48pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/13 "2021-04-19T14:48:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![waterbottles](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@waterbottles](https://discourse.mc-stan.org/u/waterbottles)\
**Post date:** [April 19, 2021, 2:49pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/14 "2021-04-19T14:49:13Z")

</div>

thank you I’ll try opening an issue there too

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [April 19, 2021, 2:53pm UTC](https://discourse.mc-stan.org/t/stan-stopped-working/21880/15 "2021-04-19T14:53:28Z")

</div>

This is very strange,

> [@waterbottles](#):
>
> error in running command cannot remove file
