Please help getting RStan to work on Windows 10

Hi,

I’m having some trouble getting the R toolchain to work on a Windows 10 PC. I found several threads on these forums (and elsewhere through Google) but didn’t find the piece of information that solves the problem. Apologies in advance for asking help with something that isn’t really an RStan problem, but after a day of failed Googling I hope someone can point out what I’m missing.

Right now I have R 3.6.2, RStudio 1.2.5033, and Rtools 3.5.0.4 - this is installed in C:\Rtools\

Here is some output on session information and diagnostics:

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

> writeLines(strsplit(Sys.getenv(“PATH”), “;”)[[1]])
C:\Rtools\bin
C:\Rtools\mingw_64\bin
C:\Program Files\R\R-3.6.2\bin
C:\Program Files\R\R-3.6.2\bin\x64
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0
C:\WINDOWS\System32\OpenSSH
C:\Program Files\Common Files\ThinPrint
C:\Program Files (x86)\Enterprise Vault\EVClient
C:\Program Files\Git\cmd
C:\Program Files\MATLAB\R2018b\runtime\win64
C:\Program Files\MATLAB\R2018b\bin
C:\Users\maum\AppData\Local\Microsoft\WindowsApps
C:\blp\DAPI
C:\blp\DAPI\DDE

> system(“g++ -v”)
[1] 127

> pkgbuild::has_rtools(debug=TRUE)
Scanning R CMD config CC…
cc_path:
‘’ does not exist
Scanning path…
ls: C:\Rtools\bin\ls.exe
gcc_path: C:\Rtools\mingw_64\bin\gcc.exe
VERSION.txt
Rtools version 3.5.0.4
Version: 3.5
Found compatible gcc on path
[1] TRUE

> pkgbuild::has_build_tools(debug=TRUE)
[1] FALSE

In addition, the above asks me if I want to install Rtools again - I declined because it’s already installed (and I don’t have admin rights on this PC so it wouldn’t work anyway).

> writeLines(readLines(“J:\Documents\.R\Makevars.win”))
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

> devtools::session_info(“rstan”)
-Session info --------------------------------------------------------------------------------------------------------
setting value
version R version 3.6.2 (2019-12-12)
os Windows 10 x64
system x86_64, mingw32
ui RStudio
language (EN)
collate English_United States.1252
ctype English_United States.1252
tz Europe/Berlin
date 2020-01-21
-Packages ------------------------------------------------------------------------------------------------------------
(…)
[1] \pggm-intra.intern/mijnmappen/MAUM/Documents/R/win-library/3.6
[2] C:/Program Files/R/R-3.6.2/library

> Rcpp::evalCpp(“1 + 1”, showOutput = TRUE)
C:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB -o “sourceCpp_3.dll” “” “file272435fc4990.cpp”
Warning message:
In system(cmd) :
‘CreateProcess’ failed to run ‘C:\Rtools\bin\make.exe -f “C:/PROGRA~1/R/R-36~1.2/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-36~1.2/share/make/winshlib.mk” -f “//pggm-intra.intern/mijnmappen/maum/Documents/.R/Makevars.win” SHLIB_LDFLAGS=’$(SHLIB_CXXLDFLAGS)’ SHLIB_LD=‘$(SHLIB_CXXLD)’ SHLIB=“sourceCpp_3.dll” WIN=64 TCLBIN=64 OBJECTS=“file272435fc4990.o”’
Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir, :
Error 1 occurred building shared library.

So to my limited knowledge it seems that the computer can find Rtools (from pkgbuild::has_rtools() ) but for some reason seems unable to use it.

Please let me know if you require any more information or if there’s anything I should try. Thanks a lot for your help!

This IMHO means R can’t run g++. On my system the output is:

Using built-in specs.
COLLECT_GCC=c:\Rtools\mingw_64\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=c:/Rtools/mingw_64/bin/../libexec/gcc/x86_64-w64-mingw32/4.9.3/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.9.3/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64 --with-gxx-include-dir=/mingw64/x86_64-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-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=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='x86_64-posix-seh, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/home/Jeroen/mingw-gcc-4.9.3/x86_64-493-posix-seh-rt_v3-s/mingw64/opt/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-zlib-static/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 4.9.3 (x86_64-posix-seh, Built by MinGW-W64 project) 
[1] 0

So it seems your RTools installation is somehow corrupted. Can you locate the g++ binary? Can you execute the binary from shell? Isn’t the file quarantined by an antivirus?

Hope that helps!

1 Like

Hi @martinmodrak thanks for the quick reply. This does seem like it could be (at least part of) the problem. I’ll have a talk with the IT people at my organization, as I don’t have the admin rights to dive into this deeper.

Thanks!