Installation and setup

For this course you need to install or upgrade R, RStudio and the tidyverse meta-package. We will help you with setting up your machine on the first day of the course.

Install

R is available for free and for most platforms: Windows, GNU/Linux and macOS.
The version required for this course is minimum 4.4.0.
As for now, the latest version is 4.4.3.

Windows

Visit the download page and choose the corresponding installer. Most probably, as indicated, you want the base one. Rtools of the same version (4.4) as your R is required for some packages used in this course.

macOS

Browse to the download page and take it from there. Be careful to choose the correct version for your macOS version, meaning if you have M1/M2 chip take the arm64 version.

If you have never compiled any software on your machine, you will need to install the Xcode command-line tool provided by Apple. It is a one-time installation with this command in a Terminal:

sudo xcode-select --install

See here for more information.

GNU/Linux

Any GNU/Linux distributions is bundled with a great package manager such as dpkg, pacman or rpm. Visit the appropriate web-page for your distribution here.

After you get the correct entry in your package manager, it should be quite easy as:

sudo apt-get install r-base r-base-dev

Install RStudio IDE

RStudio Desktop is an Integrated Development Editor wrapping and interfacing R that needs to be installed first. Pick the appropriate installer for your platform. The free-version contains everything you need.

As for now, the latest version is 2024.12.1.+563. We recommend updating if you’re using older versions.

Check RStudio

They are 4 main panels in RStudio, but as the top-left is for scripting and by default missing, the layout should looks like

Of note, the default theme is with a white background. You can change it in the Global options > Appearance > Editor theme. Here is displayed the Cobalt theme.

Install R packages from the CRAN

CRAN - the Comprehensive R Archive Network - is the general package repository for R.

The bottom-right panel holds five tabs.

  • Files
  • Plots
  • Packages
  • Help
  • Viewer

Click on the Packages tab (1.) and select the select the Install button (2.). Type dplyr in (3.). You will see the word auto-completion that helps.

It takes some time, usually 10 seconds up to several minutes for a single package depending on its size and compilation stage.

The packages can also be installed in the console (i.e. the bottom-left panel). The snapshot below shows you how to install remotes using the console:

Of note, remotes is handy when you want to install a development version, for example for a new feature or if a bug was fixed but the package not yet on CRAN.

remotes::install_github("r-lib/remotes")

Installing the meta- package tidyverse

The tidyverse is a meta-package that bundles several packages for data manipulation and visualization. You can also use the command line. Please check that you’re using version 2.0 or greater if you’re using an existing installation of R.

install.packages("tidyverse")

Testing your installation

Copy / paste the code below and you should obtain the following plot.

It ensures that you are using R version >= 4.1, readr >= 2.0 and a recent RStudio.

library(tidyverse)
stopifnot(rstudioapi::isAvailable(version_needed = "2024.12.0.369"))
read_csv("https://biostat2.uni.lu/practicals/data/swiss.csv",
         show_col_types = FALSE) |>
  pivot_longer(cols = c(Fertility, Agriculture),
               names_to = "measurement", 
               values_to = "value") |>
  ggplot(aes(x = value, y = Education, colour = measurement)) +
  geom_point() +
  geom_smooth(method = "loess", formula = "y ~ x") +
  theme_bw(14)

If not, please contact me with the error produced.