Rtools not found by R when installing packages from CRAN

冷暖自知 提交于 2021-02-04 20:38:05

问题


When install any new package I get errors saying Rtools is not found. I followed the manual install instructions for Rtools but still get the same error message.

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

It seems R is not finding Rtools. Is there anyway to fix this?

I have noticed a second issue of previously installed packages disappearing also when starting new R sessions. Could these two issues be linked?

My R version in 4.0 and I am working in Windows 64bit


回答1:


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:

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"

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

The second part with packages not being found has to do with upgrading the R version e.g. 3.5 to 3.6 or 3.6 to 4.0. If you go to Documents\R\win-library there will be a version folder with the libraries installed inside. Here is a script that will install the old libraries.

lib_loc <- "C:/Users/apdev/Documents/R/win-library/3.3"
to_install <- unname(installed.packages(lib.loc = lib_loc)[, "Package"])
to_install
install.packages(pkgs = to_install)

https://community.rstudio.com/t/reinstalling-packages-on-new-version-of-r/7670/4



来源:https://stackoverflow.com/questions/62469777/rtools-not-found-by-r-when-installing-packages-from-cran

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!