Required set-up for the course

Authors: Data Carpentry contributors - Copyright (c) Data Carpentry; Ed Stowe (adaptation for USACE)
Last update: 2025-02-03
Acknowledgements: The bulk of this section is adapted from the Data Carpentry course Data Analysis and Visualization in R for Ecologists which is licensed under CC-BY 4.0 by the authors

0.1 Preparations

These modules are designed so that learners will carry out the computing as they follow the material. Consequently, learners must have R and RStudio installed on their computers. They also need to be able to install a number of R packages, create directories, and download files.

To avoid troubleshooting during the lesson, learners should follow the instructions below to download and install everything beforehand.

USACE user’s with ACE-IT machines may need assistance from their IT departments to download R and R Studio and to install packages. Therefore, give yourself ample time to get set-up with R and R Studio before any potential training sessions.

0.1.1 Install R and RStudio

R and RStudio are two separate pieces of software:

  • R is a programming language and software used to run code written in R.
  • RStudio is an integrated development environment (IDE) that makes using R easier. In this course we use RStudio to interact with R.

If you don’t already have R and RStudio installed, follow the instructions for your operating system below. You have to install R before you install RStudio.

0.1.1.1 Operating System

0.1.1.1.1 For Windows
  • Download R from the CRAN website.
  • Run the .exe file that was just downloaded
  • Go to the RStudio download page
  • Under Installers select RStudio x.yy.zzz - Windows Vista/7/8/10 (where x, y, and z represent version numbers)
  • Double click the file to install it
  • Once it’s installed, open RStudio to make sure it works and you don’t get any error messages.
0.1.1.1.2 For MacOS
  • Download R from the CRAN website.
  • Select the .pkg file for the latest R version
  • Double click on the downloaded file to install R
  • It is also a good idea to install XQuartz (needed by some packages)
  • Go to the RStudio download page
  • Under Installers select RStudio x.yy.zzz - Mac OS X 10.6+ (64-bit) (where x, y, and z represent version numbers)
  • Double click the file to install RStudio
  • Once it’s installed, open RStudio to make sure it works and you don’t get any error messages.
0.1.1.1.3 For Linux
  • Download R from the CRAN website.
  • Select the .pkg file for the latest R version
  • Double click on the downloaded file to install R
  • It is also a good idea to install XQuartz (needed by some packages)
  • Go to the RStudio download page
  • Under Installers select RStudio x.yy.zzz - Mac OS X 10.6+ (64-bit) (where x, y, and z represent version numbers)
  • Double click the file to install RStudio
  • Once it’s installed, open RStudio to make sure it works and you don’t get any error messages.

0.1.2 Update R and RStudio

If you already have R and RStudio installed, first check if your R version is up to date:

  • When you open RStudio your R version will be printed in the console on the bottom left. Alternatively, you can type sessionInfo() into the console. If your R version is 4.0.0 or later, you don’t need to update R for this lesson. If your version of R is older than that, download and install the latest version of R from the R project website for Windows, for MacOS, or for Linux
  • It is not necessary to remove old versions of R from your system, but if you wish to do so you can check How do I uninstall R?
  • After installing a new version of R, you will have to reinstall all your packages with the new version. For Windows, there is a package called installr that can help you with upgrading your R version and migrate your package library. A similar package called pacman can help with updating R packages across To update RStudio to the latest version, open RStudio and click on Help > Check for Updates. If a new version is available follow the instruction on screen. By default, RStudio will also automatically notify you of new versions every once in a while.

0.1.3 Install required R packages

The training modules use various R packages, which are useful R code written by other people to supplement the code included in the base R language. Several of the modules use R packages specific to the analyses covered in those modules; in those instances, users will be prompted to download and load the required packages. For the first four lessons covering the introduction to R, we will use the packages tidyverse, lubridate, and ratdat, so learners planning to complete the intro to R should install these packages.

To try to install these packages, open RStudio and copy and paste the following command into the console window (look for a blinking cursor on the bottom left), then press the Enter (Windows and Linux) or Return (MacOS) to execute the command.

install.packages(c("tidyverse", "lubridate", "ratdat"))

Alternatively, you can install the packages using RStudio’s graphical user interface by going to Tools > Install Packages and typing the names of the packages separated by a comma.

R tries to download and install the packages on your machine.

When the installation has finished, you can try to load the packages by pasting the following code into the console:

If you do not see an error like there is no package called ‘...’ you are good to go!

0.1.4 Updating R packages

Generally, it is recommended to keep your R version and all packages up to date, because new versions bring improvements and important bugfixes. To update the packages that you have installed, click Update in the Packages tab in the bottom right panel of RStudio, or go to Tools > Check for Package Updates...

You should update all of the packages required for the course, even if you installed them relatively recently.

0.1.5 Download the data

We will download the data directly from R during the modules. However, if you are expecting problems with the network, it may be better to download the data beforehand and store it on your machine.

The data files for the lesson can be downloaded manually: