# Rstan not working on my machine

**URL:** <https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156>\
**Category:** RStan\
**Created:** [August 13, 2019, 12:54pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156 "2019-08-13T12:54:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewgelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewgelman/32/1577_2.png) [@andrewgelman](https://discourse.mc-stan.org/u/andrewgelman)\
**Post date:** [August 13, 2019, 12:54pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156/1 "2019-08-13T12:54:26Z")

</div>

Stan was not working on my computer so I tried the 8 schools example from the Getting Started page and it didn’t work; see below. I don’t know what to do!

> fit ← stan(file = ‘8schools.stan’, data = schools\_dat)  
> Error in compileCode(f, code, language = language, verbose = verbose) :  
> Compilation ERROR, function(s)/method(s) not created! clang: warning: no such sysroot directory: ‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk’ [-Wmissing-sysroot]  
> In file included from file3a15598c2ae2.cpp:8:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/src/stan/model/model\_header.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/i  
> In addition: Warning message:  
> In system(cmd, intern = !verbose) :  
> running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file3a15598c2ae2.cpp 2\> file3a15598c2ae2.cpp.err.txt’ had status 1  
> Error in sink(type = “output”) : invalid connection

–

Mac 10.14.6  
R version 3.6.1

> writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”)))

CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas

CC=clang  
CXX14=clang++ -arch x86\_64 -ftemplate-depth-256

> devtools::session\_info(“rstan”)  
> ─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────────  
> setting value  
> version R version 3.6.1 (2019-07-05)  
> os macOS Mojave 10.14.6  
> system x86\_64, darwin15.6.0  
> ui RStudio  
> language (EN)  
> collate en\_US.UTF-8  
> ctype en\_US.UTF-8  
> tz Europe/Paris  
> date 2019-08-13

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
package \* version date lib source  
assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0)  
backports 1.1.4 2019-04-10 [1] CRAN (R 3.6.0)  
BH 1.69.0-1 2019-01-07 [1] CRAN (R 3.6.0)  
callr 3.3.1 2019-07-18 [1] CRAN (R 3.6.0)  
checkmate 1.9.4 2019-07-04 [1] CRAN (R 3.6.0)  
cli 1.1.0 2019-03-19 [1] CRAN (R 3.6.0)  
colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.0)  
crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0)  
desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0)  
digest 0.6.20 2019-07-04 [1] CRAN (R 3.6.0)  
ellipsis 0.2.0.1 2019-07-02 [1] CRAN (R 3.6.0)  
fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0)  
ggplot2 \* 3.2.1 2019-08-10 [1] CRAN (R 3.6.0)  
glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0)  
gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.0)  
gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.0)  
inline 0.3.15 2018-05-18 [1] CRAN (R 3.6.0)  
labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)  
lattice 0.20-38 2018-11-04 [1] CRAN (R 3.6.1)  
lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.0)  
loo 2.1.0 2019-03-13 [1] CRAN (R 3.6.0)  
magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0)  
MASS 7.3-51.4 2019-03-31 [1] CRAN (R 3.6.1)  
Matrix 1.2-17 2019-03-22 [1] CRAN (R 3.6.1)  
matrixStats 0.54.0 2018-07-23 [1] CRAN (R 3.6.0)  
mgcv 1.8-28 2019-03-21 [1] CRAN (R 3.6.1)  
munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.0)  
nlme 3.1-141 2019-08-01 [1] CRAN (R 3.6.0)  
pillar 1.4.2 2019-06-29 [1] CRAN (R 3.6.0)  
pkgbuild 1.0.4 2019-08-05 [1] CRAN (R 3.6.0)  
pkgconfig 2.0.2 2018-08-16 [1] CRAN (R 3.6.0)  
plyr 1.8.4 2016-06-08 [1] CRAN (R 3.6.0)  
prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0)  
processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.0)  
ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0)  
R6 2.4.0 2019-02-14 [1] CRAN (R 3.6.0)  
RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0)  
Rcpp 1.0.2 2019-07-25 [1] CRAN (R 3.6.0)  
RcppEigen 0.3.3.5.0 2018-11-24 [1] CRAN (R 3.6.0)  
reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.6.0)  
rlang 0.4.0 2019-06-25 [1] CRAN (R 3.6.0)  
rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0)  
rstan \* 2.19.2 2019-07-09 [1] CRAN (R 3.6.0)  
scales 1.0.0 2018-08-09 [1] CRAN (R 3.6.0)  
StanHeaders \* 2.18.1-10 2019-06-14 [1] CRAN (R 3.6.0)  
stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0)  
stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0)  
tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0)  
utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.0)  
vctrs 0.2.0 2019-07-05 [1] CRAN (R 3.6.0)  
viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.0)  
withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0)  
zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.6.0)

[1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

>

---

<div class="post-metadata">

**Author:** ![jjramsey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jjramsey/32/3319_2.png) [@jjramsey](https://discourse.mc-stan.org/u/jjramsey)\
**Post date:** [August 13, 2019, 1:27pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156/2 "2019-08-13T13:27:51Z")

</div>

What is in the directory `/Library/Developer/CommandLineTools/SDKs/`?

---

<div class="post-metadata">

**Author:** ![andrewgelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewgelman/32/1577_2.png) [@andrewgelman](https://discourse.mc-stan.org/u/andrewgelman)\
**Post date:** [August 13, 2019, 1:54pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156/3 "2019-08-13T13:54:44Z")

</div>

I don’t think I have such a directory!

---

<div class="post-metadata">

**Author:** ![jjramsey](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jjramsey/32/3319_2.png) [@jjramsey](https://discourse.mc-stan.org/u/jjramsey)\
**Post date:** [August 13, 2019, 1:58pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156/4 "2019-08-13T13:58:39Z")

</div>

Well, that would certainly explain the warning.

Also, I noticed that it looks like a copy-and-paste from one of the error messages was cut off:

> [@andrewgelman](#):
>
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/i

Was there something after `StanHeaders/i` that didn’t get copied?

---

<div class="post-metadata">

**Author:** ![andrewgelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewgelman/32/1577_2.png) [@andrewgelman](https://discourse.mc-stan.org/u/andrewgelman)\
**Post date:** [August 13, 2019, 2:01pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156/5 "2019-08-13T14:01:34Z")

</div>

Below is the entire error message I got. It just seems weird because Stan used to work on my machine. Maybe I need to re-install R?

> fit ← stan(file = ‘8schools.stan’, data = schools\_dat)  
> Error in compileCode(f, code, language = language, verbose = verbose) :  
> Compilation ERROR, function(s)/method(s) not created! clang: warning: no such sysroot directory: ‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk’ [-Wmissing-sysroot]  
> In file included from file3a15598c2ae2.cpp:8:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/src/stan/model/model\_header.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:  
> In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/i  
> In addition: Warning message:  
> In system(cmd, intern = !verbose) :  
> running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file3a15598c2ae2.cpp 2\> file3a15598c2ae2.cpp.err.txt’ had status 1  
> Error in sink(type = “output”) : invalid connection

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [August 13, 2019, 2:13pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156/6 "2019-08-13T14:13:42Z")

</div>

You need to call `stan` with `verbose = TRUE` to see the actual error message, but my guess is that it is fixable by one of

> [@Dealing with Mojave](https://discourse.mc-stan.org/t/dealing-with-mojave/6519):
>
> For the first time, getting rstan to work on Windows seems to be easier than getting it to work on the Mojave version Mac OS X. Mojave seems to affect different people in different ways. Here are the things I would try if rstan is not working: Make sure you have opened Xcode once via Spotlight to accept its license If that doesn’t work but you have a /Library/Developer/CommandLineTools/Packages/macOS\_SDK\_headers\_for\_macOS\_10.14. pkg, install that so it puts C++ headers back in /usr/include I…

---

<div class="post-metadata">

**Author:** ![andrewgelman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrewgelman/32/1577_2.png) [@andrewgelman](https://discourse.mc-stan.org/u/andrewgelman)\
**Post date:** [August 13, 2019, 2:32pm UTC](https://discourse.mc-stan.org/t/rstan-not-working-on-my-machine/10156/7 "2019-08-13T14:32:22Z")

</div>

I tried verbose=TRUE but then the error message was so long that it rolled off the screen. It was larger than Rstudio’s buffer so I can’t even share the output here.

I went to the link and tried Step 1 (“Make sure you have opened Xcode once via Spotlight to accept its license”). This took a few minutes. When that was done, I closed Rstudio, uninstalled rstan and reinstalled it, and tried again and got the same error message.

I couldn’t understand Steps 2, 3, and 4, so I jumped to Step 5 (“Try `xcode-select --install` from the Terminal app or the Terminal tab of the RStudio console”) and that worked for me.

Thanks!
