Rtools not being detected by R

WindowsRRstudio

Windows Problem Overview


Update:

I've written a brief walkthrough guide to installing Rtools on windows.

Original:

I am trying to build an R package using RStudio on Windows 7. When I attempt to build the package via RStudio's Build panel I receive:

WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

http://cran.rstudio.com/bin/windows/Rtools/

Loading library(devtools) and running find_rtools(T) gives:

Scanning path...
ls : F:\Rtools\bin\ls.exe 
Scanning registry...
Found F:/Rtools for 3.1 
VERSION.txt
Rtools version 3.1.0.1936 
[1] TRUE

The Path variable is set as:

F:\Rtools\bin;F:\Rtools\gcc-4.6.3\bin;F:\Rtools\perl\bin;F:\Rtools\MinGW\bin;F:\Program Files\R\R-3.0.2\bin\x64;F:\Program Files (x86)\HTML Help Workshop;F:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Microsoft Network Monitor 3\;F:\Program Files (x86)\QuickTime\QTSystem\

I've also restarted several times, yet the error persists. I'm a bit confused as to why this is occurring.

Output when R access system variable Path:

> Sys.getenv()['PATH']
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 PATH 
"F:\\Program Files\\R\\R-3.0.2\\bin\\x64;F:\\Rtools\\bin;F:\\Rtools\\gcc-4.6.3\\bin;F:\\Rtools\\perl\\bin;F:\\Rtools\\MinGW\\bin;F:\\Program Files\\R\\R-3.0.2\\bin\\x64;F:\\Program Files (x86)\\HTML Help Workshop;F:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Common Files\\Microsoft Shared\\Windows Live;C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\Windows Live;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Windows Live\\Shared;C:\\Program Files\\Microsoft Network Monitor 3\\;F:\\Program Files (x86)\\QuickTime\\QTSystem\\" 

The R version I am using is: R version 3.0.2 (2013-09-25) -- "Frisbee Sailing."

The Rstudio Version I am using is: 0.97.551. When I check for updates, I'm told that this is the latest patch.

> Sys.which("ls.exe")
                   ls.exe 
"F:\\Rtools\\bin\\ls.exe" 
> Sys.which("gcc.exe")
gcc.exe 
     "" 

Windows Solutions


Solution 1 - Windows

Turns out when I installed RTools I left out the R 2.15.x+ toolchain option in the installation, which lead to the gcc never being installed. Hopefully, this post will serve as a diagnostic guide if RStudio fails to register RTools.

Thank you everyone for your help.

Solution 2 - Windows

The RTools install on Windows doesn't select the C compiler to include by default. I ran the install a few times blindly clicking through and got this error. I reran the installer and selected/included the 32bit and 64bit C compilers. Problem solved.

Solution 3 - Windows

I had the same error, and I had installed the tool chain (I believe).

My fix was to move the R Tools paths to the front of my PATH variable.

Solution 4 - Windows

It may as well be added that if you don't have admin rights on your computer the installation of Rtools will fail due to some missing registry permissions.

Took me quite some time to figure that out because if you install Rtools via R you won't see this alert.

So better download the .exe-file, install it as admin and tick the boxes mentioned above to get Rtools working properly.

Solution 5 - Windows

Another possible cause is for R to be looking in the wrong directory for RTools components, via https://stackoverflow.com/questions/47076620/r-cmd-check-not-looking-for-gcc-in-rtools-directory/47076968#47076968:

R uses a BINPREF variable to locate certain executables, including components of RTools.

BINPREF can be set in a number of places. In my case, it was set in C:/Users/MYUSERNAME/Documents/.R/Makevars. Deleting the contents of this file removed a link to a previous, and since deleted, installation of RTools.

It is also worth checking the file $RPATH/etc/i386/Makeconf (swap i386 for x64 if you have a 64-bit installation), which will be re-created with each new installation of R. Note the line BINPREF ?= c:/Rtools/mingw_32/bin/, which (via the ?= operator) will set the value of BINPREF if it is not already set, as it was in the Makevars file mentioned above.

A temporary fix is to replace BINPREF ?= with BINPREF =, but as the Makeconf file is overwritten when R is updated, you'll have to remember to do this each time. Better to edit, or delete, the Makevars file for a permanent change.

Solution 6 - Windows

R can't find Rtools.


90% of the time, reinstalling Rtools will solve:

  1. Go to this site
  2. Download rtools
  3. Find the file that just downloaded
  4. Double click on it to start installation
  5. Close and reopen RStudio
  6. Everything should work now!


Further reading and other possible solutions can be found here

Solution 7 - Windows

You can add Rtools to your path by typing:

writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

Solution 8 - Windows

https://cran.r-project.org/bin/windows/Rtools/

Starting with R 4.0.0 (released April 2020), R for Windows uses a brand new toolchain bundle called rtools40.

This version of Rtools upgrades the mingw-w64 gcc toolchains to version 8.3.0, and introduces a new build system based on msys2, which makes easier to build and maintain R itself as well as the system libraries needed by R packages on Windows. For more information about the latter, follow the links at the bottom of this document.

This documentation is about rtools40, the current version used for R 4.0.0 and newer. For information about previous versions of Rtools that can be used with R 3.6.3 or older, please visit this page. Installing Rtools40

Note that rtools40 is only needed build R packages with C/C++/Fortran code from source. By default, R for Windows installs the precompiled “binary packages” from CRAN, for which you do not need rtools!

To use rtools40, download the installer from CRAN:

On Windows 64-bit: rtools40-x86_64.exe (recommended: includes both i386 and x64 compilers)
On Windows 32-bit: rtools40-i686.exe (i386 compilers only)

Note for RStudio users: please check you are using the latest version of RStudio (at least 1.2.5042) to work with rtools40.

Putting Rtools on the PATH

After installation is complete, you need to perform one more step to be able to compile R packages: you need to put the location of the Rtools make utilities (bash, make, etc) on the PATH. The easiest way to do so is create a text file .Renviron in your Documents folder which contains the following line:

PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"

You can do this with a text editor, or you can even do it from R like so:

writeLines('PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"', con = "~/.Renviron")

Now restart R, and verify that make can be found, which should show the path to your Rtools installation.

Sys.which("make")

"C:\rtools40\usr\bin\make.exe"

If this works, you can try to install an R package from source:

install.packages("jsonlite", type = "source")

If this succeeds, you’re good to go! See the links below to learn more about rtools40 and the Windows build infrastructure.

Solution 9 - Windows

To download Rtools on Windows follow these steps below:

  1. Go to this CRAN website

2. Look under the heading "Installing RtoolsXX" e.g. Rtools42, there a link is provided to the index. Visit that link.

  1. On the index page, find a file named rtools42-4737-4741.exe, (where 4737-4741 are version numbers and change as new builds are being added).
  2. Download and open it to install.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncoatlessView Question on Stackoverflow
Solution 1 - WindowscoatlessView Answer on Stackoverflow
Solution 2 - WindowsAndrew RothsteinView Answer on Stackoverflow
Solution 3 - WindowsgeneoramaView Answer on Stackoverflow
Solution 4 - WindowsZapView Answer on Stackoverflow
Solution 5 - WindowsMartin SmithView Answer on Stackoverflow
Solution 6 - WindowsstevecView Answer on Stackoverflow
Solution 7 - WindowsmikeyView Answer on Stackoverflow
Solution 8 - WindowsMarcus JuniorView Answer on Stackoverflow
Solution 9 - WindowsAmrish Kumar RaiView Answer on Stackoverflow