# Error in compileCode

**URL:** <https://discourse.mc-stan.org/t/error-in-compilecode/39483>\
**Category:** RStan\
**Tags:** installation, rstan\
**Created:** [May 14, 2025, 6:44am UTC](https://discourse.mc-stan.org/t/error-in-compilecode/39483 "2025-05-14T06:44:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattansb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mattansb/32/20280_2.png) [@mattansb](https://discourse.mc-stan.org/u/mattansb)\
**Post date:** [May 14, 2025, 6:44am UTC](https://discourse.mc-stan.org/t/error-in-compilecode/39483/1 "2025-05-14T06:44:00Z")

</div>

I am teaching Stan and many of my students are getting the following error when following the [RStan Getting Started](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started) guide:

```R
remove.packages("rstan")
if (file.exists(".RData")) file.remove(".RData")
# Close all RStudio sessions 

# Open RStudio
# To install rstan, run the following code
install.packages("rstan", repos = c('https://stan-dev.r-universe.dev', getOption("repos")))

# Examine if rstan is working (there is no warning)
example(stan_model, package = "rstan", run.dontrun = TRUE)

```

```no-highlight

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Users/hatoo/AppData/Local/R/win-library/4.3/StanHeaders/include/src/stan/mcmc/hmc/hamiltonians/dense_e_metric.hpp:22:56: required from 'double stan::mcmc::dense_e_metric<Model, BaseRNG>::T(stan::mcmc::dense_e_point&) [with Model = model7a7c1af36495__namespace::model7a7c1af36495_; BaseRNG = boost::random::mixmax_engine<17, 36, 0>]'
C:/Users/hatoo/AppData/Local/R/win-library/4.3/StanHeaders/include/src/stan/mcmc/hmc/hamiltonians/dense_e_metric.hpp:21:10: required from here
C:/Users/hatoo/AppData/Local/R/win-library/4.3/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:654:74: warning: ignoring attributes on template argument 'Eigen::internal::packet_traits<double>::type' {aka '__m128d'} [-Wignored-attributes]
  654 | return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);
      | ^ ~~~~~~~~
make: *** [C:/PROGRA~1/R/R-43~1.0/etc/x64/Makeconf:272: file7a7cfee76d3.o
Error in sink(type = "output") : invalid connection

```

This is happening with fresh installations of R 4.5.0 (with RTools 45), or with 4.4.3 (with RTools 44), or with R 4.3.0 (with RTools 43) on Windows OS.

Some more information that might be relevant:

1. At least for some I can confirm that their R library is _not_ installed on some cloud drive.
2. This didn’t happen last year (🤷‍♂️)

My students and I would be grateful for any help provided!

---

<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:** [May 14, 2025, 4:51pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/39483/2 "2025-05-14T16:51:24Z")

</div>

Sorry for these issues! I’ve pushed an update which should solve things.

Can you try the steps again to remove and install `rstan`?

If you still run into errors with the example model, can you update your `Makevars.win` file to suppress compilation warnings so that the result will show the error:

```r
if (!dir.exists("~/.R")) {
  dir.create("~/.R")
}

cat("CPPFLAGS += -w -Wno-misleading-indendation", file = "~/.R/Makevars.win",
    append = TRUE)

```

EDIT: binaries updated on r-universe

---

<div class="post-metadata">

**Author:** ![mattansb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mattansb/32/20280_2.png) [@mattansb](https://discourse.mc-stan.org/u/mattansb)\
**Post date:** [May 17, 2025, 7:55pm UTC](https://discourse.mc-stan.org/t/error-in-compilecode/39483/3 "2025-05-17T19:55:39Z")

</div>

Thanks @andrjohns - that seems to have done it!

(My students thank you as well 👍)
