install.packages(c("tidyverse", "nlme", "lme4", "emmeans", "ratdat"))JEDS Introduction and Setup
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)
If the computer is managed by their organization’s IT department they might need help from an IT administrator.
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.
For Windows
- Download R from the CRAN website.
- Run the
.exefile that was just downloaded - Go to the RStudio download section of the RStudio User Guide on the Posit site
- Under Installers select Windows - RSTUDIO-xxxx.yy.z-zzz.exe (where x = year, y = month, 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.
For MacOS
- Download R from the CRAN website.
- Select the
.pkgfile 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 section of the RStudio User Guide on the Posit site
- Under Installers select Mac OS 13+ - RSTUDIO-xxxx.yy.z-zzz.dmg (where x = year, y = month, 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.
For Linux
- Click on your distribution in the Linux folder of the CRAN website. Linux Mint users should follow instructions for Ubuntu.
- Go through the instructions for your distribution to install R.
- Go to the RStudio download section of the RStudio User Guide on the Posit site
- Select the relevant installer for your Linux system (Ubuntu/Debian or Fedora)
- 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.
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
installrthat can help you with upgrading your R version and migrate your package library. A similar package calledpacmancan help with updating R packages across To update RStudio to the latest version, open RStudio and click onHelp > 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
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, emmeans, and ratdat.
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.
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)
library(ratdat)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.
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 lesson, even if you installed them relatively recently.
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
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:
- Install
gitto your computer - Make sure you have access to a shell
- 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.
- The Carpentries
gitinstallation instructions gives succinct platform-based instructions. - Happy Git with R has more detailed instructions that cover a few edge-cases.
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.