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?
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")
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
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ā
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ā
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"
Hi Laura,
The issue is caused by your setting of BINPREF
in your .Rprofile
file. See the RStan Getting Started Instructions for information on how to fix this.
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?
What do you get from:
Sys.getenv("BINPREF")
readLines("~/.Rprofile")
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
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