# Error when Configuring RStan C++ toolchain

**URL:** <https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915>\
**Category:** General\
**Tags:** rstan\
**Created:** [September 8, 2020, 12:14pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915 "2020-09-08T12:14:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aschmidt](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@aschmidt](https://discourse.mc-stan.org/u/aschmidt)\
**Post date:** [September 8, 2020, 12:14pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/1 "2020-09-08T12:14:47Z")

</div>

Hello! I am a new user to RStan and I ran into an issue when configuring the C++ toolchain and subsequent loading of the RStan package.

I am using Windows 10, R x64 v.4.0.2 and RStudio v.1.3.1073. I followed these instructions to the letter in R and RStudio: [https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started](https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started). Below are the commands I used an abbreviated version of the output highlighting the error.

```
> install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE)
ERROR: compilation failed for package 'jsonlite'
* removing 'C:/Users/Allison/Documents/R/win-library/4.0/jsonlite'
Warning in install.packages :
  installation of package ‘jsonlite’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\Allison\AppData\Local\Temp\RtmpAnUOQm\downloaded_packages’
> pkgbuild::has_build_tools(debug = TRUE)
>library("rstan") 
Loading required package: StanHeaders
Loading required package: ggplot2
Error: package or namespace load failed for ‘rstan’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘jsonlite’

```

Any insights on would be helpful.  
Thank you!  
Allison

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [September 8, 2020, 12:22pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/2 "2020-09-08T12:22:18Z")

</div>

Can you try running:

```
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

```

and restart the R ression and then try installing rstan again.

---

<div class="post-metadata">

**Author:** ![aschmidt](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@aschmidt](https://discourse.mc-stan.org/u/aschmidt)\
**Post date:** [September 8, 2020, 2:09pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/3 "2020-09-08T14:09:02Z")

</div>

Still the same error.  
Error: package or namespace load failed for ‘rstan’ in loadNamespace(j \<- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):  
there is no package called ‘jsonlite’

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [September 8, 2020, 2:19pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/4 "2020-09-08T14:19:12Z")

</div>

Can you run

install.packages(“jsonlite”)

---

<div class="post-metadata">

**Author:** ![aschmidt](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@aschmidt](https://discourse.mc-stan.org/u/aschmidt)\
**Post date:** [September 8, 2020, 3:21pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/5 "2020-09-08T15:21:18Z")

</div>

This is what I get when I try installing just the jsonlite package.

ERROR: compilation failed for package ‘jsonlite’

- removing ‘C:/Users/Allison/Documents/R/win-library/4.0/jsonlite’

The downloaded source packages are in  
‘C:\Users\Allison\AppData\Local\Temp\Rtmpu2NfgF\downloaded\_packages’  
Warning message:  
In install.packages(“jsonlite”) :  
installation of package ‘jsonlite’ had non-zero exit status

---

<div class="post-metadata">

**Author:** ![aschmidt](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@aschmidt](https://discourse.mc-stan.org/u/aschmidt)\
**Post date:** [September 8, 2020, 3:22pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/6 "2020-09-08T15:22:38Z")

</div>

Here is the complete output in case it helps.

> install.packages(“jsonlite”)  
> Installing package into ‘C:/Users/Allison/Documents/R/win-library/4.0’  
> (as ‘lib’ is unspecified)  
> — Please select a CRAN mirror for use in this session —

There is a binary version available but the source version is later:  
binary source needs\_compilation  
jsonlite 1.7.0 1.7.1 TRUE

installing the source package ‘jsonlite’

trying URL ‘[https://cran.case.edu/src/contrib/jsonlite\_1.7.1.tar.gz](https://cran.case.edu/src/contrib/jsonlite_1.7.1.tar.gz)’  
Content type ‘application/x-gzip’ length 1057786 bytes (1.0 MB)  
downloaded 1.0 MB

- installing _source_ package ‘jsonlite’ …  
\*\* package ‘jsonlite’ successfully unpacked and MD5 sums checked  
\*\* using staged installation  
\*\* libs

\*\*\* arch - i386  
C:/Rtools/mingw\_32/bin/gcc -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG -Iyajl/api -D\_\_USE\_MINGW\_ANSI\_STDIO -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c base64.c -o base64.o  
C:/Rtools/mingw\_32/bin/gcc: not found  
make: \*\*\* [base64.o] Error 127  
ERROR: compilation failed for package ‘jsonlite’

- removing ‘C:/Users/Allison/Documents/R/win-library/4.0/jsonlite’

The downloaded source packages are in  
‘C:\Users\Allison\AppData\Local\Temp\Rtmpu2NfgF\downloaded\_packages’  
Warning message:  
In install.packages(“jsonlite”) :  
installation of package ‘jsonlite’ had non-zero exit status

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [September 8, 2020, 3:33pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/7 "2020-09-08T15:33:08Z")

</div>

What does Sys.getenv(“RTOOLS40\_HOME”) return?

---

<div class="post-metadata">

**Author:** ![aschmidt](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@aschmidt](https://discourse.mc-stan.org/u/aschmidt)\
**Post date:** [September 8, 2020, 3:33pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/8 "2020-09-08T15:33:56Z")

</div>

> Sys.getenv(“RTOOLS40\_HOME”)  
> [1] “”

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [September 8, 2020, 4:36pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/9 "2020-09-08T16:36:55Z")

</div>

Oh ok, in this case you do not have RTools 4.0 installed.

See: [https://cran.r-project.org/bin/windows/Rtools/](https://cran.r-project.org/bin/windows/Rtools/)

---

<div class="post-metadata">

**Author:** ![aschmidt](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@aschmidt](https://discourse.mc-stan.org/u/aschmidt)\
**Post date:** [September 8, 2020, 4:51pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/10 "2020-09-08T16:51:43Z")

</div>

I followed the instructions to the link you sent and I get a compilation error for the jsonlite package.

> Sys.which(“make”)  
> make  
> “C:\rtools40\usr\bin\make.exe”  
> install.packages(“jsonlite”, type = “source”)  
> Installing package into ‘C:/Users/Allison/Documents/R/win-library/4.0’  
> (as ‘lib’ is unspecified)  
> trying URL ‘[https://cran.rstudio.com/src/contrib/jsonlite\_1.7.1.tar.gz](https://cran.rstudio.com/src/contrib/jsonlite_1.7.1.tar.gz)’  
> Content type ‘application/x-gzip’ length 1057786 bytes (1.0 MB)  
> downloaded 1.0 MB

- installing _source_ package ‘jsonlite’ …  
\*\* package ‘jsonlite’ successfully unpacked and MD5 sums checked  
\*\* using staged installation  
\*\* libs

\*\*\* arch - i386  
C:/Rtools/mingw\_32/bin/gcc -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG -Iyajl/api -D\_\_USE\_MINGW\_ANSI\_STDIO -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c base64.c -o base64.o  
sh: C:/Rtools/mingw\_32/bin/gcc: No such file or directory  
make: \*\*\* [C:/PROGRA~1/R/R-40~1.2/etc/i386/Makeconf:222: base64.o] Error 127  
ERROR: compilation failed for package ‘jsonlite’

- removing ‘C:/Users/Allison/Documents/R/win-library/4.0/jsonlite’  
Warning in install.packages :  
installation of package ‘jsonlite’ had non-zero exit status

The downloaded source packages are in  
‘C:\Users\Allison\AppData\Local\Temp\RtmpyI6z2r\downloaded\_packages’

---

<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:** [September 9, 2020, 12:13am UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/11 "2020-09-09T00:13:30Z")

</div>

Hi Allison,

That means that R is still configured to look for the old RTools installation. To help figure out what needs to be changed, can you post the outputs from:

```
Sys.getenv("BINPREF")
Sys.getenv("PATH")
readLines("~/.Renviron")
readLines("~/.Rprofile")
readLines("~/.R/Makevars.win")

```

---

<div class="post-metadata">

**Author:** ![aschmidt](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@aschmidt](https://discourse.mc-stan.org/u/aschmidt)\
**Post date:** [September 12, 2020, 1:32pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/12 "2020-09-12T13:32:17Z")

</div>

> Sys.getenv(“BINPREF”)  
> [1] “C:/Rtools/mingw\_$(WIN)/bin/”

> Sys.getenv(“PATH”)  
> [1] “C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.2\bin\x64;c:\Rtools\bin;c:\Rtools\mingw\_64\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32\compiler;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\;C:\Program Files (x86)\Toshiba\Bluetooth Toshiba Stack\sys\x64\;C:\MATLAB701\bin\win32;C:\Program Files\MATLAB\R2017b\runtime\win64;C:\Program Files\MATLAB\R2017b\bin;C:\Program Files (x86)\Kensington\TrackballWorks;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;”

> readLines(“~/.Renviron”)  
> [1] "PATH=${RTOOLS40\_HOME}\usr\bin;${PATH}"

> readLines(“~/.Rprofile”)  
> [1] “Sys.setenv(BINPREF = "C:/Rtools/mingw\_$(WIN)/bin/")”

> readLines(“~/.R/Makevars.win”)  
> [1] “”  
> [2] “CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2”  
> [3] “”  
> [4] “CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2”  
> [5] “”  
> [6] “CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2”  
> [7] “”  
> [8] “CXX14FLAGS=-O3 -mtune=native -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.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:** [September 13, 2020, 1:28pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/14 "2020-09-13T13:28:27Z")

</div>

Great! Three steps to take here:

- In your Documents folder there will a file called `.Rprofile`, delete that
- In your Documents folder there will be a .R folder, in that will be a `Makevars.win` file. Open that in a text editor and delete all but one of the `CXX14FLAGS` lines
- Restart R and try your model again

---

<div class="post-metadata">

**Author:** ![Laura\_Verbeek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/laura_verbeek/32/10838_2.png) [@Laura\_Verbeek](https://discourse.mc-stan.org/u/Laura_Verbeek)\
**Post date:** [March 2, 2021, 11:09am UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/15 "2021-03-02T11:09:13Z")

</div>

Hi There!

I have a similar problem. I have R version 4.0.4 with Rstudio version 1.4.1106 (both updated today). I have been trying to get the installation from source to work, but I keep getting the same error messages. I have already done all the steps from this thread, including numerous steps from other threads to get jsonlite to install. I get the following error message:

install.packages(“jsonlite”, type = “source”)  
Installing package into ‘C:/Users/laura/OneDrive/Documenten/R/win-library/4.0’  
(as ‘lib’ is unspecified)  
trying URL ‘[http://cran.rstudio.com/src/contrib/jsonlite\_1.7.2.tar.gz](http://cran.rstudio.com/src/contrib/jsonlite_1.7.2.tar.gz)’  
Content type ‘application/x-gzip’ length 421716 bytes (411 KB)  
downloaded 411 KB

- installing _source_ package ‘jsonlite’ …  
\*\* package ‘jsonlite’ successfully unpacked and MD5 sums checked  
\*\* using staged installation  
\*\* libs

\*\*\* arch - i386  
C:/rtools40/usr/mingw\_32/bin/gcc -I"C:/PROGRA~1/R/R-40~1.4/include" -DNDEBUG -Iyajl/api -D\_\_USE\_MINGW\_ANSI\_STDIO -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c base64.c -o base64.o  
sh: C:/rtools40/usr/mingw\_32/bin/gcc: No such file or directory  
make: \*\*\* [C:/PROGRA~1/R/R-40~1.4/etc/i386/Makeconf:222: base64.o] Error 127  
ERROR: compilation failed for package ‘jsonlite’

- removing ‘C:/Users/laura/OneDrive/Documenten/R/win-library/4.0/jsonlite’
- restoring previous ‘C:/Users/laura/OneDrive/Documenten/R/win-library/4.0/jsonlite’  
Warning in install.packages :  
installation of package ‘jsonlite’ had non-zero exit status

The downloaded source packages are in  
‘C:\Users\laura\AppData\Local\Temp\Rtmpctpahf\downloaded\_packages’

---

<div class="post-metadata">

**Author:** ![Laura\_Verbeek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/laura_verbeek/32/10838_2.png) [@Laura\_Verbeek](https://discourse.mc-stan.org/u/Laura_Verbeek)\
**Post date:** [March 2, 2021, 11:10am UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/16 "2021-03-02T11:10:55Z")

</div>

Btw, my output to the code metioned above is as following:

Sys.getenv(“BINPREF”)  
[1] “C:/rtools40/usr/mingw\_$(WIN)/bin/”

> Sys.getenv(“PATH”)  
> [1] “C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.4\bin\x64;C:\Python27\Lib\site-packages\PyQt4;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\MATLAB\R2019a\bin;C:\Python27;C:\Python27\DLLs;C:\Python27\Scripts;C:\Python27\gnuplot\binary;C:\Program Files (x86)\pythonxy\SciTE-3.5.1-4;C:\Program Files (x86)\pythonxy\console;C:\Users\laura\AppData\Roaming\TinyTeX\bin\win32;C:\Users\laura\AppData\Local\Microsoft\WindowsApps;C:\Users\laura\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64”  
> readLines(“~/.Renviron”)  
> [1] “PATH="{RTOOLS40\_HOME}\\usr\\bin;{PATH}"”  
> readLines(“~/.Rprofile”)  
> [1] “Sys.setenv(BINPREF = "C:/rtools40/usr/mingw\_$(WIN)/bin/")”  
> readLines(“~/.R/Makevars.win”)  
> [1] “”  
> [2] " CXX14FLAGS += -mtune=native -O3 -mmmx -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.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:** [March 4, 2021, 12:41pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/17 "2021-03-04T12:41:24Z")

</div>

Hi Laura,

The issue is caused by your setting of `BINPREF` in your `.Rprofile` file. See the [RStan Getting Started Instructions](https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows#r40) for information on how to fix this.

---

<div class="post-metadata">

**Author:** ![Laura\_Verbeek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/laura_verbeek/32/10838_2.png) [@Laura\_Verbeek](https://discourse.mc-stan.org/u/Laura_Verbeek)\
**Post date:** [March 4, 2021, 5:03pm UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/18 "2021-03-04T17:03:36Z")

</div>

Hi there,

Thank you for your quick reply! I had already deleted my Rprofile file before, but there was a new one now. I again deleted it, as was in the instructions. The problem is still there though. Do you have any idea how I can fix it?

---

<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:** [March 5, 2021, 12:12am UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/19 "2021-03-05T00:12:33Z")

</div>

What do you get from:

```
Sys.getenv("BINPREF")
readLines("~/.Rprofile")

```

---

<div class="post-metadata">

**Author:** ![Laura\_Verbeek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/laura_verbeek/32/10838_2.png) [@Laura\_Verbeek](https://discourse.mc-stan.org/u/Laura_Verbeek)\
**Post date:** [March 5, 2021, 6:50am UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/20 "2021-03-05T06:50:21Z")

</div>

The first one gives:

Sys.getenv(“BINPREF”)  
[1] “”

And the second one:

readLines("~/.Rprofile")  
Error in file(con, “r”) : cannot open the connection  
In addition: Warning message:  
In file(con, “r”) :  
cannot open file ‘C:/Users/laura/OneDrive/Documenten/.Rprofile’: No such file or directory

---

<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:** [March 5, 2021, 7:03am UTC](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915/21 "2021-03-05T07:03:54Z")

</div>

If you restart your R session and run the example model:

```
example(stan_model,package="rstan",run.dontrun=T)

```

What error do you get? If you’re still getting an error now that the `.Rprofile` file has been deleted then there is a different issue to be fixed

[Next page](https://discourse.mc-stan.org/t/error-when-configuring-rstan-c-toolchain/17915.md?page=2)
