Rtools not being detected by R
Asked Answered
C

9

68

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 
     "" 
Corn answered 10/11, 2013 at 1:52 Comment(9)
Check Sys.getenv()['PATH'] to see if that's the path in R, too.Maurya
I get the same path only with \\ vs. the single \ in PATH environment. The path output contains the same above. I would post it, but the comment limits my character count.Corn
Okay. That was the source of the problem back when I got this error, so I'm out of ideas. Maybe you should tag this with rstudio (in addition to windows and r)...?Maurya
It sounds like devtools is finding it but RStudio is not, so you can use the devtools functions (e.g. build) instead. You don't say which version of Rstudio you're using - make sure you have the latest version, and if it still doesn't work report the bug at support.rstudio.orgGrig
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.Corn
What output do you see for Sys.which("ls.exe") and Sys.which("gcc.exe")? RStudio expects both of those to be on the path, and inside the Rtools directory.Agglutinative
> Sys.which("ls.exe") ls.exe "F:\\Rtools\\bin\\ls.exe" > Sys.which("gcc.exe") gcc.exe "" So, it looks like gcc isn't being found?Corn
Exact same problem when installing Rtools on a new machine. My problem was complicated by the fact that I already had 32bit MinGW installed, so Rcpp files were compiling on 32bit R but not 64bit R. Mystifying until I read this.Lobate
See this answer for a possible work-around: https://mcmap.net/q/296758/-rtools-is-not-being-detected-from-rstudioLowspirited
C
21

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.

Corn answered 14/11, 2013 at 5:20 Comment(7)
For another possible solution for this error message see: https://mcmap.net/q/296759/-r-3-3-0-installing-a-package-on-windows-gcc-not-found-errorLowspirited
Please don't do these kinds of redirects to another question that redirects to yet another question. The issue you supply is relating to RStudio not detecting Rtools on a custom path. This is a bug that has been fixed depending on the RStudio version.Corn
How would someone check if they installed the toolchain or not? Perhaps Sys.which("gcc.exe")?Obeah
@Obeah the toolchain will be located at C:\Rtools under a default install. Alternative, in R, try Sys.getenv('PATH'). If running into issues, try moving the location in PATH to the top.Corn
@Corn wow, thanks for the immediate response. I found the fix (moving RTools up in my path) and added the answer already.Obeah
@Obeah no problem. Thanks for guest lecturing in FA 17 for STAT 385! :)Corn
what is fascinating about this is that this RStudio bug regularly rears its ugly head; for example RStudio Desktop 1.2.5033 again has major difficulties with Rtools not being in C:\Rtools after RStudio Desktop 1.1.464 handling it quite well. One also should mention that in most cases (as long as the BINPREFs are set correctly) plain vanilla RGui has no problem whatsoever with pkg installation from type "source"! So it is really a major RStudio bug here and you can always fall back to RGui - just in case!Polygamous
O
7

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.

Obeah answered 24/1, 2019 at 0:34 Comment(4)
I had to add C:\rtools40\usr\bin to PATH on windowsHorary
@SahilSingh just updated my R to 4.0, and the rtools path seems to have changed from Rtools/bin to rtools40/usr/binObeah
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")Exceedingly
One should also restart R after that test with Sys.which("make")Shoemaker
C
6

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.

Crandall answered 20/2, 2014 at 5:53 Comment(0)
T
5

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.

Tallie answered 20/7, 2016 at 12:24 Comment(0)
C
3

You can add Rtools to your path by typing:

writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
Corinthians answered 6/7, 2020 at 15:48 Comment(0)
Q
2

Another possible cause is for R to be looking in the wrong directory for RTools components, via R CMD check not looking for gcc in Rtools directory:

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.

BINPREF should point to the folder that contains gcc; in R4.3 on Windows 10, this reads <PATH TO RTOOLS>/rtools43/x86_64-w64-mingw32.static.posix/bin/.

Quadrisect answered 10/6, 2019 at 11:43 Comment(0)
O
1

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

Outstay answered 20/12, 2020 at 1:31 Comment(0)
R
0

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.

Rhearheba answered 27/3, 2021 at 23:32 Comment(0)
H
-1

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. 3. 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). 3. Download and open it to install.

Harumscarum answered 23/3, 2022 at 5:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.