简体   繁体   中英

Rtools not being detected by R

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 
     "" 

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.

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.

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.

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.

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 Make conf file is overwritten when R is updated, you'll have to remember to do this each time. Better to edit, or delete, the Make vars file for a permanent change.

您可以通过键入以下内容将 Rtools 添加到您的路径中:

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

This error message may appear for Windows users , when the windows user you're logged in as doesn't have permission to add files, or when an anti virus program quarantines (with or without your knowledge) some key files during the R installation.

Often, you can solve this by giving the windows user the required permissions

Background:

  • I tried install.packages("Rtools") but it did not help Rtools isn't an R package, but a standalone installer which cannot be installed via install.packages() (thanks @coatless)
  • After the windows user had the required permissions, things like `install.packages("tidyverse") succeeded (there was no need to try to reinstall Rtools).
  • Often after turning off anti-virus, uninstalling R, then reinstalling R, everything will work as expected.

Alternatively, try downloading rtools separately here and simply run the .exe file downloaded to install it - that worked for me.

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.

To download Rtools on Windows follow these steps below:

  1. Go to this CRAN website

2. Look under the heading "Installing RtoolsXX" eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM