4.8 Packages

While you can write your own functions, most functions you use will be part of a package. In R, the fundamental unit of shareable code is the package. A package bundles together code, data, documentation, and tests, and is easy to share with others. As of July 2018, there were over 14,000 packages available on the Comprehensive R Archive Network, or CRAN, the public clearing house for R packages. This huge variety of packages is one of the reasons that R is so successful.

Installing a package using RStudio requires selecting the Install Packages Button in the Files, Plots, Packages Pane

In the pop up box that results simply type the name of the package and check “install dependencies” and click Install

Its also possible for you to install and load packages from the console. Always make sure to put the package name in quotes when installing and setting dependencies = True

install.packages("tidyverse", dependencies = TRUE)    
library(tidyverse)

You only need to install a package once, but you need to reload it every time you start a new session.