RStan instalation issues Failed with error: ‘package ‘rstan’

rstan

#1

I am currently reading Rethinking Statistics by McElreath and tried to install Rstan for my R Studio session as shown in the guide. Since it did not work I have undertaken the following steps below. However, it still does not work. What am I missing?
I…

  • uninstalled R

  • uninstalled R-Studio

  • Restarted the computer

  • Clean Registry with CC Cleaner

  • Restart the computer

  • Installed R 3.4.3

  • Installed RStudio-1.1.442

On


it is reccomended, to “Choose the most recent “frozen” version that supports the version of R you have installed”
However, there is no Frozen Version that is compatible with the recent R version 3.4.3 So I downloaded Rtools34.exe that is compatible with “R 3.3.x and later” but not frozen. I then…

  • Installed Rtools34 according to the guide and clicked the checkbox in the setup wizard for the system PATH

  • opened R-Studio

  • Sys.getenv(“PATH”) returns:

> Sys.getenv("PATH")
[1] "C:\\Rtools\\bin;C:\\Program Files\\R\\R-3.4.3\\bin\\x64;c:\\Rtools\\bin;c:\\Rtools\\mingw_32\\bin;c:\\Rtools\\bin;c:\\Rtools\\gcc-4.6.3\\bin;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x86;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x64;C:\\Program Files\\ThinkPad\\Bluetooth Software\\;C:\\Program Files\\ThinkPad\\Bluetooth Software\\syswow64;C:\\Program Files (x86)\\Intel\\Services\\IPT\\;C:\\Program Files (x86)\\Skype\\Phone\\;C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\""
  • checking whether g++ can be called:

system(‘g++ -v’)
Using built-in specs.
COLLECT_GCC=c:\Rtools\mingw_32\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=c:/Rtools/mingw_32/bin/…/libexec/gcc/i686-w64-mingw32/4.9.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: …/…/…/src/gcc-4.9.3/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-static --disable-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion=‘i686-posix-dwarf, Built by MinGW-W64 project’ --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS=’-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include’ CXXFLAGS=’-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include’ CPPFLAGS= LDFLAGS=’-pipe -L/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/lib -Wl,–large-address-aware’
Thread model: posix
gcc version 4.9.3 (i686-posix-dwarf, Built by MinGW-W64 project)

  • and

system(‘where make’)
C:\Rtools\bin\make.exe

  • I then executed this code:

dotR <- file.path(Sys.getenv(“HOME”), “.R”)
if (!file.exists(dotR))
dir.create(dotR)
M <- file.path(dotR, “Makevars”)
if (!file.exists(M))
file.create(M)
cat("\nCXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function",
file = M, sep = “\n”, append = TRUE)

  • Since Rtools was installed under \Rtools I execute
cat('Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")',
    file = file.path(Sys.getenv("HOME"), ".Rprofile"), 
    sep = "\n", append = TRUE)
  • I did NOT excecute the code below, since I wanted to keep verbose warnings because installing RStan hasn’t worked previously

  • installed RStan via

install.packages(“rstan”, repos = “https://cloud.r-project.org/”, dependencies=TRUE)

  • …and confirmed the prompt to restart R-Studio

  • I got asked a second time, confirmed

  • again, confirmed…

  • The consol returned some errors:

C:/Users/User/Documents/.R/Makevars

install.packages(“rstan”, repos = “https://cloud.r-project.org/”, dependencies=TRUE)
Error in install.packages : Updating loaded packages

Restarting R session…

install.packages(“rstan”, repos = “https://cloud.r-project.org/”, dependencies = TRUE)
Error in install.packages : Updating loaded packages

Restarting R session…

install.packages(“rstan”, repos = “https://cloud.r-project.org/”, dependencies = TRUE)
Error in install.packages : Updating loaded packages

Restarting R session…
… So I deleted the “s” in https

  • confirmed the restart…
  • confirmed the restart…
  • declined the restart to see what happens…

Installing package into ‘C:/Users/User/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
trying URL ‘http://cloud.r-project.org/bin/windows/contrib/3.4/rstan_2.17.3.zip
Content type ‘application/zip’ length 3340284 bytes (3.2 MB)
downloaded 3.2 MB

package ‘rstan’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘rstan’

The downloaded binary packages are in
C:\Users\User\AppData\Local\Temp\Rtmp8wwMwn\downloaded_packages

  • and after a restart I get this error message:

Loading required package: rethinking
Failed with error: ‘package ‘rstan’ required by ‘rethinking’ could not be found’
Error in .requirePackage(package) :
unable to find required package ‘rethinking’
Loading required package: rethinking
Failed with error: ‘package ‘rstan’ required by ‘rethinking’ could not be found’
Error in .requirePackage(package) :
unable to find required package ‘rethinking’

So it seems to me that R can’t find RStan after all. What am I missing?


#2

You need a clean R session that does not have rstan loaded before you can reinstall rstan. Also, it can help to uninstall rstan via

remove.packages("rstan")

before doing

install.packages("rstan")

#3

Thanks! it worked. I also installed an older R-version just to make sure that I can use the frozen Rtools 3.3 version. Than you very much!