CmdStanR can't find Rtools

I have installed rtools4.0, R version 4.1.2, The mingw32-make, gcc, rtools, all are working, however the rcmdstan is having issues of installing cmdstan and finding the rtools4.0. Please find below some code:

Sys.which(“make”)
make
“C:\rtools40\usr\bin\make.exe”

system(“mingw32-make -v”)
GNU Make 4.2.1
Built for x86_64-w64-mingw32
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[1] 0

system(“gcc -v”)
Using built-in specs.
COLLECT_GCC=C:\rtools40\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: …/gcc-8.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran --disable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion=‘Built by Jeroen for the R-project’ --with-bugurl=https://github.com/r-windows --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 8.3.0 (Built by Jeroen for the R-project)
[1] 0

system(“g++ -v”)
Using built-in specs.
COLLECT_GCC=C:\rtools40\mingw64\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: …/gcc-8.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran --disable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion=‘Built by Jeroen for the R-project’ --with-bugurl=https://github.com/r-windows --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 8.3.0 (Built by Jeroen for the R-project)
[1] 0

install_cmdstan(cores = 4)
Error:
RTools 4.0 was not found but is required to run CmdStan with R version 4.x.
Please install RTools 4.0 and run check_cmdstan_toolchain().

check_cmdstan_toolchain()
Error:
RTools 4.0 was not found but is required to run CmdStan with R version 4.x.
Please install RTools 4.0 and run check_cmdstan_toolchain().

Would appreciate any suggestions. Thanks in advance for your time.

I don’t know much about Windows so hopefully @rok_cesnovar or someone else will have some ideas, but until then what happens if you try fix=TRUE with check_cmdstan_toolchain()?

check_cmdstan_toolchain(fix = TRUE)

There are only a small number of things it knows how to fix, so I’m not sure if that will help but worth a try until somebody more knowledgable about Windows can offer suggestions.

Thanks Jonah. I tried fix=TRUE too …

check_cmdstan_toolchain(fix = TRUE)
Error:
RTools 4.0 was not found but is required to run CmdStan with R version 4.x.
Please install RTools 4.0 and run check_cmdstan_toolchain().

Oh well, worth a shot! Sorry it’s not working. Let’s see what @rok_cesnovar or other Windows people say.

Given that you are using R 4.X, the issue seems to be that you do not have the RTOOLS40_HOME environment variable set. CmdStanR relies on that variable to detect whether and where Rtools is installed.

This is a bit odd to me that it is missing, given that Rtools 4.0 installation sets that environment variable automatically on install. Maybe it got removed somehow.

There are three options you have to resolve this:

  • reinstall RTools 4.0 so that the environment variable is set (I would recommend this)
  • set the variable in .Renviron using (restart R session afterwards):
write('RTOOLS40_HOME="C:\\rtools40"', file = "~/.Renviron", append = TRUE)
1 Like

Fantastic! Thanks @rok_cesnovar . Yes, the RTOOLS40_HOME env was somehow removed, although Sys.which(“make”) was working. The second option worked for me. Thanks again. Cheers.

2 Likes

Great! Updated the post with the typo fixed.