# Error: cannot allocate vector of size 17348.7 Gb

**URL:** <https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615>\
**Category:** RStan\
**Created:** [April 27, 2020, 1:56am UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615 "2020-04-27T01:56:57Z")\
**Posts on this page:** 9\
**Page:** 2

<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 3, 2020, 5:34am UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/21 "2020-05-03T05:34:18Z")

</div>

In your R HOME directory (usually the Documents folder on Windows), you should have a `.Rprofile` file (you can check where this is using: ` file.path(Sys.getenv("HOME"), ".Rprofile")`).

Open up that file with a text editor (like Notepad) and delete the line: `Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")`

After that, restart R and run:

```
Sys.which("g++")

```

If that returns something with `C:\\rtools40` at the start, you should be good to go

---

<div class="post-metadata">

**Author:** ![Elchorro](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@Elchorro](https://discourse.mc-stan.org/u/Elchorro)\
**Post date:** [May 30, 2020, 2:37pm UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/22 "2020-05-30T14:37:15Z")

</div>

Hi all,

I had similar error after updating to R4.0. My model no longer run.

Turned out it was enough to remove compiled models and recompile with new RTools.

Hope someone will find this useful.

---

<div class="post-metadata">

**Author:** ![itsdanwall](https://avatars.discourse-cdn.com/v4/letter/i/aca169/32.png) [@itsdanwall](https://discourse.mc-stan.org/u/itsdanwall)\
**Post date:** [June 10, 2020, 5:05pm UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/23 "2020-06-10T17:05:21Z")

</div>

I had the same issue and had to go into my R library and uninstall Rcpp and reinstall both it and rstan. I’m wondering if I updating packages prior to installing updated rtools was the culprit.

Thanks for all of your help!

---

<div class="post-metadata">

**Author:** ![Unai\_Vicente](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/unai_vicente/32/8328_2.png) [@Unai\_Vicente](https://discourse.mc-stan.org/u/Unai_Vicente)\
**Post date:** [June 11, 2020, 2:39pm UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/24 "2020-06-11T14:39:43Z")

</div>

Yep, same here, reinstalling both rcpp and rstan did the trick.

---

<div class="post-metadata">

**Author:** ![Aldo\_Compagnoni](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/aldo_compagnoni/32/11025_2.png) [@Aldo\_Compagnoni](https://discourse.mc-stan.org/u/Aldo_Compagnoni)\
**Post date:** [March 24, 2021, 12:59am UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/25 "2021-03-24T00:59:43Z")

</div>

I cannot solve this issue; I am running R version 4.0.4, Rtools 4.0, Rstudio 1.4.1106, on Windows 10 on a brand new laptop (first time installing R, Rtools, and Rstudio).

I thought that running:

install.packages(c(“Rcpp”, “RcppEigen”, “rstan”), type = “source”)

would do the trick, but Rcpp cannot install because:

error: C:/Users/ac22qawo/Documents/R/R-4.0.4/library/rstan/lib/x64/libStanServices.a: No such file or directory  
no DLL was created

Also, running Sys.getenv(“BINPREF”) returns “”, and so does running Sys.which(“g++”).

This all started because when compiling a simple model of the mean to fit a dataset with a few data points, the output was:

Error: cannot allocate vector of size 15842.6 Gb  
In addition: Warning message:  
In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :  
‘C:/rtools40/usr/mingw\_/bin/g++’ not found

---

<div class="post-metadata">

**Author:** ![Aldo\_Compagnoni](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/aldo_compagnoni/32/11025_2.png) [@Aldo\_Compagnoni](https://discourse.mc-stan.org/u/Aldo_Compagnoni)\
**Post date:** [April 26, 2021, 4:45pm UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/26 "2021-04-26T16:45:14Z")

</div>

Apologies: indeed, by correctly removing Rcpp from my machine, and by recompiling old STAN models, the trick worked!

---

<div class="post-metadata">

**Author:** ![JiyueQin](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jiyueqin/32/12274_2.png) [@JiyueQin](https://discourse.mc-stan.org/u/JiyueQin)\
**Post date:** [July 21, 2021, 8:22pm UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/27 "2021-07-21T20:22:32Z")

</div>

thank you so much.  
this solved my problem.

---

<div class="post-metadata">

**Author:** ![matthewclark1223](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/matthewclark1223/32/12013_2.png) [@matthewclark1223](https://discourse.mc-stan.org/u/matthewclark1223)\
**Post date:** [January 10, 2022, 12:55pm UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/28 "2022-01-10T12:55:42Z")

</div>

Having this same issue. When you all talk about “recompiling old STAN models” as a fix for the problem, do you mean rerun all the models which use the STAN script I am trying to run? Just confused about which STAN models rerun exactly.

---

<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:** [January 10, 2022, 1:21pm UTC](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615/29 "2022-01-10T13:21:08Z")

</div>

Any Stan models which were compiled prior to R4.x, with the `auto_write=TRUE` setting will have created an `.rds` file in the same directory as the stan model with the pre-compiled model. If you delete these `.rds` files then the models will be re-compiled under the new RTools

[Previous page](https://discourse.mc-stan.org/t/error-cannot-allocate-vector-of-size-17348-7-gb/14615.md?page=1)
