The source of this document is available on gitlab.
Last version: 2020-04-15

Rstudio

Table of Contents

Installing RStudio and R

There are many different ways to install R and RStudio on your computer. The one we recommend, and describe in the following, uses the package manager conda. It has the advantage of working more or less identically under Linux, Windows, and macOS. Another advantage is that the conda ecosystem contains a wide range of scientific software, which you might want to use for your own projects. If you are an experienced systems administrator, you are of course free to choose another approach to installing software, it's only the result that matters.

First, download the most recent version of Miniconda. Miniconda is a lightweight edition of Anaconda, a software distribution that includes Python, R, Jupyter, and many popular libraries for scientific computing and data science.

Install Miniconda following the supplied instructions. Whenever (it it not systematic) the installer asks you the question

Do you wish the installer to initialize Miniconda3 by running conda init? [yes|no]

answer yes. You will then see the advice

=> For changes to take effect, close and re-open your current shell. <=

which you must respect to make sure that the following steps work correctly.

Important: You should then run all the following commands through the conda shell. As explained in the Anaconda documentation, to open the Anaconda prompt:

The first command to run next is

conda update -n base -c defaults conda

which updates all the software in the conda distribution.

We can now create a conda environment for the RStudio path of out MOOC:

conda create -n mooc-rr-rstudio

and activate it:

conda activate mooc-rr-rstudio

It is not strictly necessary to activate an environment in order to use it, but doing so makes the use of the environment easier and less error prone. You have to perform this activation step every time you open a new terminal, before you can work with the environment.

The next step is the installation of all software packages we need and which are in the Miniconda distribution:

conda install rstudio r r-ggplot2 r-reticulate python

We also need one package that is not in Miniconda, so we request it from the independent package source conda-forge:

conda install -c conda-forge r-parsedate

You can now start RStudio directly from the command line:

rstudio

Under Windows and macOS, you might be tempted to start RStudio from the graphical user interface. It is in fact not so difficult to find RStudio.app in the conda environment and open it directly. But you have to resist that temptation. If you don't run RStudio from the command line, it won't be able to detect the conda environment that you activated.

LaTeX for generating PDF files

If you want to convert your notebooks to PDF files, you must als install LaTeX on your computer. We explain this step in a separate resource.

RStudio documentation

The RStudio team has created a lot of very good material and tutorials. You should definitively look at the Cheat sheets webpage. In particular you may want to have look at the following ones:

In case it helps, here are some (sometimes outdated) French versions of these documents:

Using Git from RStudio

This part is the subject of a specific resource.