# Problem with rstan & R-4.0.5 on Windows

**URL:** <https://discourse.mc-stan.org/t/problem-with-rstan-r-4-0-5-on-windows/21965>\
**Category:** RStan\
**Tags:** rstan\
**Created:** [April 19, 2021, 6:49am UTC](https://discourse.mc-stan.org/t/problem-with-rstan-r-4-0-5-on-windows/21965 "2021-04-19T06:49:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fortiana](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/fortiana/32/10858_2.png) [@fortiana](https://discourse.mc-stan.org/u/fortiana)\
**Post date:** [April 19, 2021, 6:49am UTC](https://discourse.mc-stan.org/t/problem-with-rstan-r-4-0-5-on-windows/21965/1 "2021-04-19T06:49:54Z")

</div>

After updating to R-4.0.5 rstan has broken. Code which previously was working crashes when calling stan. It seems the problem is some environment variable but I am unable to corrrect it.  
(This happens for every model)

The error message is as follows:

# Translate model to C++ and compile to DSO:

stanDso ← stan\_model( model\_code=modelString )

Error in inDL(x, as.logical(local), as.logical(now), …): unable to load shared object ‘C:/Users/josep/AppData/Local/Temp/Rtmpw5K3Oc/file413c70f952de.dll’:  
LoadLibrary failure: A dynamic link library (DLL) initialization routine failed.

Traceback:

1. stan\_model(model\_code = modelString)

2. cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap("",  
. model\_name, “");”, sep = “”), includes = inc, plugin = “rstan”,  
. save\_dso = save\_dso | auto\_write, module\_name = paste(“stan\_fit4”,  
. model\_cppname, “\_mod”, sep = “”), verbose = verbose)

3. pkgbuild::with\_build\_tools(cxxfunction(sig = sig, body = body,  
. plugin = plugin, includes = includes, settings = settings,  
. …, verbose = verbose), required = rstan\_options(“required”) &&  
. !identical(Sys.getenv(“WINDOWS”), “TRUE”) && !identical(Sys.getenv(“R\_PACKAGE\_SOURCE”),  
. “”))

4. withr::with\_path(rtools\_path(), code)

5. force(code)

6. cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes,  
. settings = settings, …, verbose = verbose)

7. dyn.load(libLFile)

8. inDL(x, as.logical(local), as.logical(now), …)  
Error in sink(type = “output”): invalid connection  
Traceback:

9. stan\_model(model\_code = modelString)

10. cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap("",  
. model\_name, “");”, sep = “”), includes = inc, plugin = “rstan”,  
. save\_dso = save\_dso | auto\_write, module\_name = paste(“stan\_fit4”,  
. model\_cppname, “\_mod”, sep = “”), verbose = verbose)

11. sink(type = “output”)

---

<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, 7:51am UTC](https://discourse.mc-stan.org/t/problem-with-rstan-r-4-0-5-on-windows/21965/2 "2021-04-19T07:51:24Z")

</div>

Can you restart R (making sure that rstan doesn’t get loaded) and run:

```r
remove.packages(c("StanHeaders", "rstan")) 

# Compile packages using all cores 
Sys.setenv(MAKEFLAGS = paste0("-j",parallel::detectCores()))

install.packages(c("StanHeaders","rstan"),type="source")

```

---

<div class="post-metadata">

**Author:** ![fortiana](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/fortiana/32/10858_2.png) [@fortiana](https://discourse.mc-stan.org/u/fortiana)\
**Post date:** [April 19, 2021, 9:34am UTC](https://discourse.mc-stan.org/t/problem-with-rstan-r-4-0-5-on-windows/21965/3 "2021-04-19T09:34:08Z")

</div>

Thanks so much! It worked!!

I must say however, that whereas rstan compilation finished Ok, it gave an ENORMOUS quantity of fearful warnings and errors.

---

<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, 9:48am UTC](https://discourse.mc-stan.org/t/problem-with-rstan-r-4-0-5-on-windows/21965/4 "2021-04-19T09:48:54Z")

</div>

Great! Those are fine to ignore
