Introduction

Compiled code in R is the zeitgeist echoing throughout all corridors of user styles. The advent of Rcpp and the afforded seamless transition between R objects and C++ objects has yielded countless accolades. However, there is a gatekeeper to enabling Rcpp outside of the R environment: A compiler. Enter into the picture Rtools, which provides a toolchain to compile code with R for Windows.

Prerequisite

In order to follow this installation guide, you must:

  1. Be on Windows 7 or greater.
  2. Have R version 3.3.0 or greater.
    • Rtools radically changed before then
  3. Be able to launch an application via “Run as Administrator” prompt.

R Compilers for Other Platforms

This installation guide is specific to Windows operating systems >= Windows 7.

If you are on MacOS, please see: http://thecoatlessprofessor.com/programming/r-compiler-tools-for-rcpp-on-os-x/

For those of you on Linux, you can either use:

# RHEL/CentOS
sudo yum update
sudo yum install R

# Ubuntu
sudo apt-get update
sudo apt-get install r-base r-base-dev

Install Guide

The steps below will guide you through setting up the Rtools toolchain on Windows. The version these steps are done for is Rtools 3.4. Generally, each R point release (x.y.0) yields an equivalent Rtools release.

Installation Steps

  • Step 3: Open the folder location where Rtools can be found.
  • Step 4: Right click on the “Rtools34.exe” and select “Run as administrator”

  • Step 4: Accept the UAC prompt that appears

  • Step 5: Select the appropriate language and press “OK”

  • Step 6: Press “Next” to begin the install process

  • Step 7: Agree to the terms of the licenses used by the toolchain by pressing “Next”.

  • Step 8: Select the install directory for Rtools and press “Next”.
    • I strongly recommend against switching away from the default.
    • Default directory: c:\Rtools

  • Step 9: Ensure only the installer is following the “Package authoring installation” guidelines and press “Next”.

  • Step 10: Elect to modify the Windows PATH variable to contain a reference to where the Rtools install directorys are by pressing “Next”.

  • Step 11: Ensure that the PATH variable in the following order before pressing “Next”.
    • c:\Rtools\bin;
    • c:\Rtools\mingw_32\bin;

  • Step 12: Note the changes to the installer will make before pressing “Next” to begin installing each component.

  • Step 13: Wait patiently as Rtools installs on your system….

  • Step 14: Rejoice as Rtools is now installed on your system!

If you are unsure of manually downloading the program, please use the installr package to download and install Rtools.

# install.packages("installr")
library("installr")
install.Rtools()

This will automatically download Rtools and give you the previous installer prompts.

Verifying Install

Open your IDE of choice and type:

install.packages("Rcpp")
Rcpp::evalCpp("2+2")

If the output is not a number (psst 4), then there is an issue with the Rtools install. Please google the error and let us know about it!

Common Issues

Failure to install Rcpp prior to calling Rcpp::evalCpp("2+2") yields:

Error in if (grepl(“ “, path, fixed = TRUE)) path <- utils::shortPathName(path) :

argument is of length zero

In addition: Warning messages:

1: In read.dcf(file.path(p, “DESCRIPTION”), c(“Package”, “Version”)) :

cannot open compressed file ‘C:/Users/yivic/OneDrive/Documents/R/win-library/3.3/Rcpp/DESCRIPTION’,

probable reason ‘No such file or directory’