Error when Configuring RStan C++ toolchain

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. 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

Can you try running:

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

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

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’

Can you run

install.packages(“jsonlite”)

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

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
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

What does Sys.getenv(“RTOOLS40_HOME”) return?

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

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

See: https://cran.r-project.org/bin/windows/Rtools/

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
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’

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")

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® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel® 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”

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
1 Like