# Problem with R update to 4.0.2 on MacOS: stan stuck in model fit

**URL:** <https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664>\
**Category:** RStan\
**Created:** [August 26, 2020, 12:01pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664 "2020-08-26T12:01:33Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![jsal](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@jsal](https://discourse.mc-stan.org/u/jsal)\
**Post date:** [August 29, 2020, 4:24pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/21 "2020-08-29T16:24:53Z")

</div>

Interesting. First running

```
rstan_options(javascript = FALSE)

```

Then the model

```
> fit <- stan(model_code=model, data = schools_dat, verbose=T)

```

causes the same stuck process, but this time I get an Apple spinning colorwheel and cannot Esc out of the process, which I could do before.

---

<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 29, 2020, 5:31pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/22 "2020-08-29T17:31:09Z")

</div>

And

```
example(cxxfunction, package = "inline", run.dontrun = TRUE)

```

works?

---

<div class="post-metadata">

**Author:** ![jsal](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@jsal](https://discourse.mc-stan.org/u/jsal)\
**Post date:** [August 29, 2020, 6:28pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/23 "2020-08-29T18:28:34Z")

</div>

No, still the same.

```
> rstan_options(javascript = FALSE)
> 
> example(cxxfunction, package = "inline", run.dontrun = TRUE)

cxxfnc> # default plugin
cxxfnc> fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , '
cxxfnc+ return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
cxxfnc+ ' )

```

And even after quitting out of the console, activity monitor still shows an R process running in the background.

---

<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 29, 2020, 7:26pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/24 "2020-08-29T19:26:55Z")

</div>

OK. This is probably an issue with your toolchain, rather than something specific to Stan. @coatless might have previously encountered someone with this hanging under

```
R 4.0.2
Mac OS X Mojave or High Sierra
No Makevars file
No Renviron file
Fresh install of the latest RStan
```

---

<div class="post-metadata">

**Author:** ![coatless](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/coatless/32/2052_2.png) [@coatless](https://discourse.mc-stan.org/u/coatless)\
**Post date:** [September 8, 2020, 1:45pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/25 "2020-09-08T13:45:54Z")

</div>

Odd, not sure why `RStan` is hanging in this instance.

Few quick questions:

1. Could you try a simple _C++_ statement?

```
Rcpp::evalCpp("1 + 1", verbose = TRUE)

```

1. What is the full session information?

```
sessionInfo()

```

1. What is the output from:

```
cat(readLines(file.path(Sys.getenv("HOME"), ".R", "Makevars")), sep = "\n")

```

1. What happens if you try:

```
update.packages(ask = FALSE, checkBuilt = TRUE)

```

Another consideration, but maybe upgrade from macOS Mojave 10.14.6 to macOS Catalina 10.15?

---

<div class="post-metadata">

**Author:** ![jsal](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@jsal](https://discourse.mc-stan.org/u/jsal)\
**Post date:** [September 8, 2020, 6:28pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/26 "2020-09-08T18:28:33Z")

</div>

Thanks much. I’m reporting outputs here from a machine running Mohave, but I get the same behavior on a different machine I just upgraded to Catalina (and did a fresh R and RStan install on).

```
> Rcpp::evalCpp("1 + 1", verbose = TRUE)

Generated code for function definition: 
--------------------------------------------------------

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
SEXP get_value(){ return wrap( 1 + 1 ) ; }

Generated extern "C" functions 
--------------------------------------------------------

#include <Rcpp.h>
// get_value
SEXP get_value();
RcppExport SEXP sourceCpp_1_get_value() {
BEGIN_RCPP
    Rcpp::RObject rcpp_result_gen;
    Rcpp::RNGScope rcpp_rngScope_gen;
    rcpp_result_gen = Rcpp::wrap(get_value());
    return rcpp_result_gen;
END_RCPP
}

Generated R functions 
-------------------------------------------------------

`.sourceCpp_1_DLLInfo` <- dyn.load('/private/var/folders/_t/y8rbmtzj4jz0qxpl_bt_wqlw0000gp/T/Rtmpf0xuzk/sourceCpp-x86_64-apple-darwin17.0-1.0.5/sourcecpp_131e1414200d5/sourceCpp_2.so')

get_value <- Rcpp:::sourceCppFunction(function() {}, FALSE, `.sourceCpp_1_DLLInfo`, 'sourceCpp_1_get_value')

rm(`.sourceCpp_1_DLLInfo`)

Building shared library
--------------------------------------------------------

DIR: /private/var/folders/_t/y8rbmtzj4jz0qxpl_bt_wqlw0000gp/T/Rtmpf0xuzk/sourceCpp-x86_64-apple-darwin17.0-1.0.5/sourcecpp_131e1414200d5

/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB -o 'sourceCpp_2.so' 'file131e138e8e1d3.cpp' 
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include" -I"/private/var/folders/_t/y8rbmtzj4jz0qxpl_bt_wqlw0000gp/T/Rtmpf0xuzk/sourceCpp-x86_64-apple-darwin17.0-1.0.5" -I/usr/local/include -fPIC -Wall -g -O2 -c file131e138e8e1d3.cpp -o file131e138e8e1d3.o
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -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 sourceCpp_2.so file131e138e8e1d3.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
[1] 2
> 

```

And,

```
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6

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

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base     

loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2 Rcpp_1.0.5    
> 

```

And,

```
> cat(readLines(file.path(Sys.getenv("HOME"), ".R", "Makevars")), sep = "\n")
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/Users/jdsal/.R/Makevars': No such file or directory
> 

```

Then following

```
update.packages(ask = FALSE, checkBuilt = TRUE)

```

I get the same hanging behavior as described above if I run the schools example.

---

<div class="post-metadata">

**Author:** ![coatless](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/coatless/32/2052_2.png) [@coatless](https://discourse.mc-stan.org/u/coatless)\
**Post date:** [September 9, 2020, 8:52pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/27 "2020-09-09T20:52:45Z")

</div>

I’m not sure what’s going on exactly.

My suggestion is double check whether Xcode CLI is up-to-date. I think a new update was released recently.

Try to update with Software Update in System Preferences or open up Terminal and type:

```
softwareupdate --all --install --force

```

If that doesn’t provide an option to upgrade Xcode CLI, please remove the old version and update to a newer one:

```bash
 sudo rm -rf /Library/Developer/CommandLineTools
 sudo xcode-select --install

```

---

<div class="post-metadata">

**Author:** ![jsal](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@jsal](https://discourse.mc-stan.org/u/jsal)\
**Post date:** [September 10, 2020, 11:41am UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/28 "2020-09-10T11:41:33Z")

</div>

I really appreciate the help. I updated to Catalina (10.15.6). I followed this [Reinstall compiler tools for MacOS](https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/). hellowworld.cpp worked, but the schools example caused the same hanging.

Following [https://discourse.mc-stan.org/t/rstan-compilation-hangs/15150](https://discourse.mc-stan.org/t/rstan-compilation-hangs/15150) I did from-scratch install of XCode CLI, R, and RStan. Still no fix.

---

<div class="post-metadata">

**Author:** ![jsal](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@jsal](https://discourse.mc-stan.org/u/jsal)\
**Post date:** [June 3, 2021, 10:44pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/29 "2021-06-03T22:44:35Z")

</div>

Hi folks. I gave up on this thread back in September, without solving the hanging problem. Ended up reverting to R v3.6x to get work done.

I recently upgraded to R 4.1.0 for a few reasons, and with fresh updates and installs of Rccp, RStan, and CLI. Hopefully revisiting this again someone can help. Here’s the session info:

```
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

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

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base     

other attached packages:
[1] dplyr_1.0.6 plyr_1.8.6 rethinking_2.13 rstan_2.21.2 ggplot2_3.3.3 StanHeaders_2.21.0-7

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6 pillar_1.6.1 compiler_4.1.0 prettyunits_1.1.1 tools_4.1.0 pkgbuild_1.2.0 lattice_0.20-44 jsonlite_1.7.2 lifecycle_1.0.0   
[10] tibble_3.1.2 gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.11 cli_2.5.0 curl_4.3.1 mvtnorm_1.1-1 loo_2.4.1 coda_0.19-4       
[19] gridExtra_2.3 withr_2.4.2 generics_0.1.0 vctrs_0.3.8 stats4_4.1.0 grid_4.1.0 tidyselect_1.1.1 glue_1.4.2 inline_0.3.19     
[28] R6_2.5.0 processx_3.5.2 fansi_0.5.0 purrr_0.3.4 callr_3.7.0 magrittr_2.0.1 MASS_7.3-54 codetools_0.2-18 matrixStats_0.59.0
[37] scales_1.1.1 ps_1.6.0 ellipsis_0.3.2 shape_1.4.6 colorspace_2.0-1 V8_3.4.2 utf8_1.2.1 RcppParallel_5.1.4 munsell_0.5.0     
[46] crayon_1.4.1      
>

```

---

<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:** [June 4, 2021, 12:37am UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/30 "2021-06-04T00:37:50Z")

</div>

Can you try the preview of the next version of `rstan` to see if the problem is still there?

Restart R,making sure that `rstan` doesn’t get loaded and run:

```r
remove.packages(c("StanHeaders", "rstan"))
    install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
    install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

```

---

<div class="post-metadata">

**Author:** ![jsal](https://avatars.discourse-cdn.com/v4/letter/j/a9adbd/32.png) [@jsal](https://discourse.mc-stan.org/u/jsal)\
**Post date:** [June 4, 2021, 6:36pm UTC](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664/31 "2021-06-04T18:36:33Z")

</div>

> [@andrjohns](#):
>
> `install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))`

This worked! Andrew, you just fixed a 10-month problem, you are amazing.  
thanks!!

[Previous page](https://discourse.mc-stan.org/t/problem-with-r-update-to-4-0-2-on-macos-stan-stuck-in-model-fit/17664.md?page=1)
