Installing R and Rtools on Windows

Installing R for Windows

  1. Download the latest version of R from CRAN (https://cran.r-project.org/bin/windows/base/)

  2. For newer versions of Windows (Windows 8 or 10 for instance), you need the 64 bit version. Install using the downloaded exe file. The default installation location is C:\Program Files\R. I recommend you to keep using this.

  3. After the installation is complete, navigate to C:\Program Files\R\R-4.0.2\bin\x64 a typical installation would show you the following files in this directory:

open.exe
R.dll
R.exe
Rblas.dll
Rcmd.exe
Rfe.exe
Rgraphapp.dll
Rgui.exe
Riconv.dll
Rlapack.dll
Rscript.exe
RSetReg.exe
Rterm.exe
  1. After that add R to Path.

Use this link (https://www.java.com/en/download/help/path.xml) for best textual instructions or follow the summary below:

  • Edit Environment Variables
  • Open Path variable
  • Add C:\Program Files\R\R-4.0.2\bin\x64 to the Path
  • x64 refers to 64 bit system, on all modern Windows version (like Windows 8, 10) you would have a 64 bit architecture See image below for a step-by-step overview:
  1. Optional (but recommended) install RStudio
  2. Check if R was succesfully installed and Path was correctly updated
  • Open Command Prompt (aka Terminal) Windows + R --> CMD
  • Type R --version in the Command Prompt
  • If you see the version you downloaded (Step 1) in the output, then everything went well

PS: You can also read the instructions from https://cran.r-project.org/bin/windows/base/README.R-4.0.2, which is a bit more verbose (but also more complete) than this

Rtools

  1. Install R-tools from https://cran.r-project.org/bin/windows/Rtools/index.html

Rtools is quite useful for installing some packages. Read more about it from the above URL

  1. Accept the default locations, R-tools should get installed in your C drive i.e. C:\rtools40
  2. Open R (in RStudio or in Terminal) and write and run the following two commands after each other
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', 
con = "~/.Renviron")

Sys.which("make")

The output after the second command should be

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

If you get the above output (or something similar). All done! You can stop reading.

But if you don’t get the above output in your R console, but get

>
""

Then read below.

For fresh installations of R, Rtools might not get installed properly. The following steps are to fix when Rtools doesn’t work on your machine. Check by writing in R: Sys.which("ls") If this also returns

>
""

Then try to restart your R session. In RStudio (Ctrl+Shift+F10). If using R from the Terminal, then quit with q() and retry.

If the error still persists, you have not correctly added R to the PATH (Step 4). Check that again. Sometimes restarting your computer can also help.

TLDR: Typical culprit for Rtools not working is incorrect Path or you need to restart