For R versions R-4.0.0 to to R-4.1.3, R for Windows uses a toolchain bundle called Rtools 4.0. This version of Rtools is based on msys2, which makes easier to build and maintain R itself as well as the system libraries needed by R packages on Windows. The latest builds of Rtools 4.0 contain 3 toolchains:
C:\rtools40\mingw32
: the 32-bit gcc-8-3.0 toolchain for R 4.0 - 4.1C:\rtools40\mingw64
: the 64-bit gcc-8-3.0 toolchain for R 4.0 - 4.1C:\rtools40\ucrt64
: a 64-bit gcc-10.3.0 ucrt toolchain (note the officially supported toolchain for R >= 4.2.0 is available here: RTools 4.2)The msys2 documentation gives an overview of the supported environments in msys2 and a comparison of MSVCRT and UCRT. The main difference between upstream msys2 and rtools4 is that our toolchains and libraries are configured for static linking, whereas upstream msys2 prefers dynamic linking. The references at the bottom of this document contain more information.
Rtools 4.0 has been maintained by Jeroen Ooms. Older editions were put together by Prof. Brian Ripley and Duncan Murdoch.
Note that Rtools 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 rtools, download the installer from CRAN:
Note for RStudio users: you need at least RStudio version 1.2.5042
to work with rtools4.
After installation is complete, you need to perform one more step to be able to compile R packages: we put the location of the Rtools make utilities (bash
, make
, etc) on the PATH
. The easiest way to do so is by creating 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 from R like so (note that in R code you need to escape backslashes):
write('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', file = "~/.Renviron", append = TRUE)
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"
Now 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 rtools4 and the Windows build infrastructure.
More documentation about using rtools4 for R users and package authors:
Advanced information about building R base and building system libraries: