R Installation Instructions

The following instructions describe how to set up all the software you will need for the “R Boot Camp,” “Mixed Models in R,” “Data Viz Basics,” “Machine Learning Demystified,” and the R part of “R for SAS Users” courses on your own machine.

What you need to install

You will need to have the following software installed on your laptop. Note that not all packages are needed for every workshop.

In addition, you will need to download the example datasets and code worksheets.

Step 1. Install R

You will need to download R from The Comprehensive R Archive Network, or CRAN.

CRAN R download screenshot

Go to the CRAN website and select the link to download the most recent version of R for your operating system. Follow the installation instructions. You will need admin rights to do this so you may need to get help from your IT staff.

Step 2. Install RStudio

RStudio is an additional software program that makes it easy for you to write R code. It provides an interface that lets you run code, edit scripts, see what variables are in your working environment, and manage files. RStudio is a program that makes it easier to use R, but you need to download both R and RStudio separately.

Posit RStudio download screenshot

As of early November 2022, RStudio is distributed by a company called Posit. Go to the RStudio Desktop download page and download the free version of RStudio Desktop. Again, you will need admin rights to do this on your USDA machine.

Step 3. Install R packages

To install the packages we will be working with in this course, you will need to either install packages by typing a command into the R console, or install them using RStudio’s package installation window.

NOTE: On some Windows systems, the default R package installation directory is inside the Program Files directory. Please ask your IT person to change the default R package installation directory to one that you have administrator rights to. This will allow you to install R packages in the future without involvement from an administrator.

Installing packages from the R console
install.packages(c("tidyverse", "lme4", "lmerTest", "nlme", "emmeans", "multcomp", "easystats", "agridat", "glmmTMB", "DHARMa", "patchwork", "pbkrtest", "multcompView", "qqplotr", "kernlab", "glmnet", "ggcorrplot", "caret", "randomForest"))
Installing packages from the RStudio package installation window

You can also install the packages using the RStudio package installation dialog.

tidyverse, lme4, lmerTest, nlme, emmeans, multcomp, easystats, agridat, glmmTMB, DHARMa, patchwork, pbkrtest, multcompView, qqplotr, kernlab, glmnet, ggcorrplot, caret, randomForest

It should look like this (with a few more package names listed):

RStudio package installation dialog

Step 4. Download the worksheets and example datasets

Go back to the main page and download the .zip files containing the example datasets and worksheets needed for the lessons. Unzip them to a directory on your local file system. You will need to specify the file path to that directory when you load the example datasets during the workshop.