An Overview of Packages

To use a package in R, you first need to make sure that it has been installed into a local library.[13] By default, packages are read from one system-level library, but you can add additional libraries.

Next, you need to load the packages into your current session. You might be wondering why you need to load packages into R in order to use them. First, R’s help system slows down significantly when you add more packages to search. (I know this from personal experience: I loaded dozens of packages into R while writing this book, and the help system slowed to a crawl.) Second, it’s possible that two packages have objects with the same name. If every package were loaded into R by default, you might think you were using one function but really be using another. Even worse, it’s possible for there to be internal conflicts: two packages may both use functions with names like “fit” that work very differently, resulting in strange and unexpected results. By loading only packages that you need, you can minimize the chance of these conflicts.



[13] If you’re a C/C++ programmer, don’t get confused; “library” means something different in R.

Get R in a Nutshell, 2nd Edition 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.