Path problem installing RStan in RStudio in 64-bit Windows 10

I installed RStan according to the instructions on

system(‘g++ -v’)
Using built-in specs.
COLLECT_GCC=C:\RTools\3.4\mingw_32\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=C:/RTools/3.4/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/i6…
Thread model: posix
gcc version 4.9.3 (i686-posix-dwarf, Built by MinGW-W64 project)

Sys.getenv(‘PATH’)
[1] “C:\Program Files\R\R-3.4.0\bin\x64;C:\RTools\3.4\bin;C:\RTools\3.4\mingw_32\bin;C:\RTools\3.4\bin;C:\RTools\3.4\mingw_64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Users\WoodwardS\AppData\Local\Microsoft\WindowsApps;C:\MinGW\bin”

It looks like Rstan is looking for g++ on the E drive for some reason?

fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

  • return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
  •                        ' )
    

E:/Rtools/mingw_64/bin/g++: not found
make: *** [file27ec5b0168e9.o] Error 127
Warning message:
running command ‘make -f “C:/PROGRA~1/R/R-34~1.0/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-34~1.0/share/make/winshlib.mk” -f “C:/Users/WoodwardS/Documents/.R/Makevars” SHLIB_LDFLAGS=’(SHLIB_CXXLDFLAGS)' SHLIB_LD='(SHLIB_CXXLD)’ SHLIB=“file27ec5b0168e9.dll” WIN=64 TCLBIN=64 OBJECTS=“file27ec5b0168e9.o”’ had status 2

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
1:
2: // includes from the plugin
3: #include <R.h>
4: #include <Rdefines.h>
5: #include <R_ext/Error.h>
6:
7:
8: // user includes
9:
10:
11: // declarations
12: extern “C” {
13: SEXP file27ec5b0168e9( SEXP x, SEXP y) ;
14: }
15:
16: // definition
17:
18: SEXP file27ec5b0168e9( SEXP x, SEXP y ){
19:
20: return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
21:
22: Rf_warning(“your C++ program does not return anything”);
23: return R_NilValue ;
24: }
25:
26:
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! E:/Rtools/mingw_64/bin/g++: not found
make: *** [file27ec5b0168e9.o] Error 127
Warning message:
running command ‘make -f “C:/PROGRA~1/R/R-34~1.0/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-34~1.0/share/make/winshlib.mk” -f “C:/Users/WoodwardS/Documents/.R/Makevars” SHLIB_LDFLAGS=’(SHLIB_CXXLDFLAGS)' SHLIB_LD='(SHLIB_CXXLD)’ SHLIB=“file27ec5b0168e9.dll” WIN=64 TCLBIN=64 OBJECTS=“file27ec5b0168e9.o”’ had status 2
In addition: Warning message:
running command ‘C:/PROGRA~1/R/R-34~1.0/bin/x64/R CMD SHLIB file27ec5b0168e9.cpp 2> file27ec5b0168e9.cpp.err.txt’ had status 1

fx( 2L, 5 ) # should be 10
Error in fx(2L, 5) : could not find function “fx”

I found the answer here

You have to edit the path in the following line. Beats me why Rtools just doesn’t install in this directory.

cat(‘Sys.setenv(BINPREF = “C:/Rtools/mingw_$(WIN)/bin/”)’,
file = file.path(Sys.getenv(“HOME”), “.Rprofile”),
sep = “\n”, append = TRUE)

1 Like