Introduction

Welcome to the Jornada Environmental Data Science education site (JEDS!). Our aim is to teach introductory and intermediate elements of data science (data management, analysis, statistics, visualization, etc.) to Jornada researchers using open-source software tools, and real data from the Jornada.

Setup for an R lesson

Many JEDS tutorials use the R programming language, and additional packages from the R software ecosystem, as the primary software tools, especially for statistical analysis. During R-based JEDS workshops we teach using the RStudio development environment as our primary programming and analysis environment. For working through these tutorials, either on your own or in a workshop, you should have both installed according to the instructions below.

The section below borrows heavily from the “Data Carpentry: Data Analysis and Visualization in R for Ecologists” lesson (Eunice, 2022)

Install R and RStudio

R and RStudio are two separate pieces of software:

  • R is a programming language that is especially powerful for data exploration, visualization, and statistical analysis
  • 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.

Windows

  • Download R from the CRAN website.
  • Run the .exe file that was just downloaded
  • Go to the RStudio download page
  • Under All Installers, download the RStudio Installer for Windows.
  • 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.
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 All Installers, download the RStudio Installer for MacOS.
  • 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.
Linux
  • Follow the instructions for your distribution from CRAN, they provide information to get the most recent version of R for common distributions. For most distributions, you could use your package manager (e.g., for Debian/Ubuntu run sudo apt-get install r-base, and for Fedora sudo yum install R), but we don’t recommend this approach as the versions provided by this are usually out of date. In any case, make sure you have at least R 3.3.1.
  • Go to the RStudio download page
  • Under All Installers, select the version that matches your distribution and install it with your preferred method (e.g., with Debian/Ubuntu sudo dpkg -i rstudio-YYYY.MM.X-ZZZ-amd64.deb at the terminal).
  • Once it’s installed, open RStudio to make sure it works and you don’t get any error messages.

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?
  • Note: The changes introduced by new R versions are usually backwards-compatible. That is, your old code should still work after updating your R version. However, if breaking changes happen, it is useful to know that you can have multiple versions of R installed in parallel and that you can switch between them in RStudio by going to Tools > Global Options > General > Basic.
  • 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.

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.

Install required R packages

During the course we will need a number of R packages. Packages contain useful R code written by other people. In most workshops we will use the packages tidyverse, nlme, lme4, and emmeans.

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", "nlme", "lme4", "emmeans"))

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 load the packages by pasting the following code into the console:

library(tidyverse)
library(nlme)
library(lme4)
library(emmeans)

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

NOTE that if you are attending a workshop, you will likely receive additional instructions about packages required for for your workshop. It is a good idea to install these in advance, using commands like those above, and let your instructors know if you have any problems.

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....

Sometimes, package updates introduce changes that break your old code, which can be very frustrating. To avoid this problem, you can use a package called renv. It locks the package versions you have used for a given project and makes it straightforward to reinstall those exact package version in a new environment, for example after updating your R version or on another computer. However, the details are outside of the scope of this lesson.

Download the data

We will download the data directly from R during the lessons. 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 here: https://doi.org/10.6084/m9.figshare.1314459

A copy of all data files used in these lessons are stored in the data/ directory of the GitHub repository. The data files you need for lessons will be specified at the start of the lesson materials, and you may also receive additional information from instructors before for workshops.

Setup for shell, git and GitHub lessons

git is a distributed version control system and is the underlying technology behind GitHub, the web-based software development and collaboration platform. It is common to use git together with a “shell”, which is a command-line interface to your computer. So, for JEDS tutorials that involve git and GitHub, please complete three steps using the recommended resources:

  1. Install git to your computer
  2. Make sure you have access to a shell
  3. Sign up for a GitHub account

If you are on MacOS or Linux, you should have a shell installed already, just make sure you can open it. For Windows you can install git and the bash shell together. There are two good resources for getting git and related software ready for a one of the JEDS tutorials.

If you want, you can also install a GUI client for git to help visualize and manage what is happening with repositories you are working with. A few recommended clients are GitKraken, SourceTree, and GitHub Desktop. More discussion of clients is available over at Happy Git with R.

Preparing for JEDS workshops

These workshops are based on “live coding,” so instructors will be running example R code while learners are expected to follow along on their own machine. To follow along successfully during a JEDS workshop, please ensure you have a laptop or other Windows, MacOS, or Linux device that has R and RStudio, and any necessary R packages, installed and up to date. Look for instructions provided by instructors in advance of the workshop about what R packages to install, and any other materials you may need to download or bring. Also, always bring a charger for your device.

If the workshop is in a virtual format we will be using the Zoom platform, so make sure you have Zoom installed and up-to-date on your machine as well.