2.5 Install packages

As I mentioned earlier, one of the great benefits of R is its community of users and the many packages they’re willing to share with the rest of us. It’s time to start installing a few.

There are a couple of main sources for R packages. One is CRAN, the Comprehensive R Archive Network. Packages must go through an approval process to be listed on CRAN, and can be installed right from the RStudio command console with install.packages("NameOfPackage"). A lot of other R packages are available on GitHub, a developers’ platform for sharing code. We’ll be installing from both sources.

First, some of my favorite CRAN packages. There’s a group of packages designed to work together that Hadley Wickham named the “tidyverse,” called that because they aim to create and analyze so-called “tidy” (well-structured) data. A number of people both within and outside of RStudio have since contributed to these packages. You probably won’t need everything in the tidyverse to run code in this book. But with a single install command, you’ll get several of my favorites, including dplyr for data wrangling and ggplot2 for visualization. Install the tidyverse with

You may be asked to pick a CRAN mirror (if so, select one from the list) and a location for your package library on your system. This installs more than two dozen R packages, so it may take awhile. But you should only need to do this once for each system you use to run R.

Another package I suggest you install now is rio:

for importing various types of data files into R.

And finally, please install the pacman package, which I’ll be using in most of the book to make sure you’ve got the proper packages installed and loaded for each chapter.

We’ll be installing other packages later on.