6.5 Load data from an external R package

Many packages have to be explicitly downloaded and installed in order to use their functions and datasets. Note that this is a two-step process: 1. Download package from internet 1. Explicitly tell R to load it

6.5.1 Step 1: Downloading packages with install.packages()

There are a number of ways to download packages. One of the easiest is to use the function install.packages(). Note that it might be better to call this “download.packages” since after you install it, you also have to load it!

Frequently in this book I will include install.packages(…) at the beginning of a lesson the first time we use a package to make sure the package is downloaded. Note, however, that if you already have downloaded the package, running install.packages(…) will download a new copy.

We’ll download a package used for plotting called ggplot2, which stands for “Grammar of Graphics.”

install.packages("ggplot2")

Often when you download a package you’ll see a fair bit of red text, and sometime other things will pop up. Usually there’s nothing of interest here, but sometimes you need to read things carefully over it for hints about why something didn’t work.