Search code examples
rrtools

How to set Rtools PATH for R


I am having trouble with rtools. Sys.which("make") yields an empty vector (working from R Studio)

Sys.which("make")

""

This is my R Version

R.Version()$version.string

[1] "R version 4.1.3 (2022-03-10)"

Apparently, this is an issue with my PATH.

Sys.getenv("PATH")

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\...\Miniconda3;C:\Users\...\Miniconda3\Library\mingw-w64\bin;C:\Users\...\Miniconda3\Library\usr\bin;C:\Users\...\Miniconda3\Library\bin;C:\Users\...\Miniconda3\Scripts;C:\Users\...\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\...\AppData\Local\Programs\Python\Python39\;C:\Users\...\AppData\Local\Microsoft\WindowsApps;C:\Users\...\AppData\Local\Programs\Microsoft VS Code\bin"

I have tried to set the PATH to rtools the following.

I have created a ~/.Renviron file

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

I also have tried this one

file.edit(file.path("~", ".Rprofile"))
Sys.setenv(PATH = paste("C:/Rtools/bin", Sys.getenv("PATH"), sep=";"))

However, still no luck. How do I set the path to rtools?


Solution

  • This is how I solved it:

    1. By looking at my PATH variable, which you get through

    Sys.getenv("PATH")

    I saw that it pointed rtools to c:\rtools40\. However, this should be c:\rtools40\usr\bin. I edited the environment Variable accordingly. Here is an instruction how to edit the environment variables on windows.

    1. I also added this to the .Renviron file:

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

    The .Renviron file should be created/located accordingly to this location

    Sys.getenv("HOME")