6.1 Introduction
When you install R you get base R, which is the core set of functions, functionality, and some data sets. Base R however is surrounded by a universe of extensions built by statistician, programmers, academics and businesses that use R for analyses. A lot of R’s functionality is found in these packages, including data sets, special plotting functions, and statistical tools for the analysis of complex data. Some of these are fairly standard and are downloaded along with base R and just need to be explicitly installed. Other have to be downloaded from the internet and installed. Most packages contain data in order to demonstrate what they do; working with data from packages will be covered in a later lesson.
This book relies heavily on an R package I’ve written called “wildlifeR” (https://brouwern.github.io/wildlifeR/) that contains the datasets used throughout the book, as well as some helpful R functions I’ve written.
Most R packages you’ll use are stored on the CRAN website where you download R (https://cran.r-project.org/). R and RStudio have functions and tools for downloading and managing packages that we’ll briefly introduce in this exercise.
Another place a package can be stored online is a code repository like GitHub. The wildlifeR package lives on GitHub and can be downloaded directly from there. Many packages on CRAN also occur on GitHub, especially if programmers are actively developing, updating, and managing the package. We’ll cover downloading packages from GitHub in the next exercise.
6.1.1 Learning objectives
This exercise will introduce students to
- the concept of an R Package (aka library)
- how to load R packages using the library() function
- the R plotting package ggplot2
- cool add-ons to ggplot2, ggpubr and cowplot
6.1.2 Learning goals
By the end of this exercise students should be able to
- locate and download packages from the CRAN website using RStudio
- recognize the R functions used to download and install packages.
6.1.3 Functions & Arguements
- install.packages
- dependencies = TRUE
- library
6.1.4 Packages
- MASS
- ggplot2
- ggpubr
- cowplot
6.1.5 Potential hangups
- quoted vs. unquoted text (eg qplot vs. ggpubr syntax)