Chapter 10. Packages

R is not limited to the code provided by the R Core Team. It is very much a community effort, and there are thousands of add-on packages available to extend it. The majority of R packages are currently installed in an online repository called CRAN (the Comprehensive R Archive Network[28]), which is maintained by the R Core Team. Installing and using these add-on packages is an important part of the R experience.

We’ve just seen the plyr package for advanced looping. Throughout the rest of the book, we’ll see many more common packages: lubridate for date and time manipulation, xlsx for importing Excel files, reshape2 for manipulating the shape of data frames, ggplot2 for plotting, and dozens of others.[29]

Chapter Goals

After reading this chapter, you should:

  • Be able to load packages that are installed on your machine
  • Know how to install new packages from local files and via the Internet
  • Understand how to manage the packages on your machine

Loading Packages

To load a package that is already installed on your machine, you call the library function. It is widely agreed that calling this function library was a mistake, and that calling it load_package would have saved a lot of confusion, but the function has existed long enough that it is too late to change it now. To clarify the terminology, a package is a collection of R functions and datasets, and a library is a folder on your machine that stores the files for a package.[30]

If you have a standard version of R—that ...

Get Learning R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.