Software installation

In order to work with R you will need to complete the following two tasks:

In principle, R scripts can be written in any text editor, but in this class we use RStudio IDE.

Installing R

  • Visit the official R website.
  • Select the version corresponding to your operating system (Linux, Mac OS, Windows).
  • Download a binary file and follow the installation instructions for your system.

Installing RStudio

Install the latest version of RStudio. RStudio includes many cool features including interactive R Notebooks, which are R Markdown documents, with chunks of code that can be executed independently and interactively and whose output is visible immediately beneath the input.

  • Visit the following RStudio website.
  • Download the correct installer for your operating system (Linux, Mac OS, Windows).
  • After the download is completed, you can double-click the file and follow the instructions to install the program.

Running R

Interpreter mode

To start the R console, you can either

  • launch the R graphical user interface; or
  • type “R” from the command line.

To open a terminal window use:

  • For Mac: Command + space. Then, start typing “Terminal” and press Enter.
  • For Windows: WinKey + R. Then, type “cmd” and press Enter.
  • For Linux: you better know how to find a terminal.

Then, you can interactively give instructions to the computer, using the R commands. To quit enter q().

The R console is also available as one of the panes in the RStudio IDE, and is automatically started when you launch RStudio.

Scripting mode

A more convenient way to interact with R is to write a script, which is a file containing all the code you want to execute. You should write your R code in the editor and, once you are finished, you can execute it from the terminal as follows:

  • from the terminal, browse to the location where you saved your script “script.R”,
  • then call “Rscript script.R”.

Using R Markdown / R Notebook

In RStudio you can start a new document of type R Notebook / R Markdown, which lets you combine text, code and the output of your code in the same report. The code in these documents is organized in chunks which can be evaluated inline, i.e., their output will be included right beneath the code. R Markdown requires you to compile the entire document, whereas R Notebooks allow you to evaluate each chunk individually, not necessarily in the order in which they appear.

You can find more information on R Notebooks here.