Chapter 2 Packages

You can think of packages as addons that extend R’s core functionality. You can browse all available packages on CRAN. To make it easier to find what you might be interested in, you can also browse the CRAN Task Views. Each package has a landing page that summarises its dependencies, version number etc. For example, for the dplyr package: Take a look at the Downloads section, and especially at the Reference Manual and Vignettes:

Vignettes are valuable documents; inside vignettes, the purpose of the package is explained in plain English, usually with accompanying examples. The reference manuals list the available functions inside the packages. You can also find vignettes from within Rstudio:

Go to the Packages pane and click on the package you’re interested in. Then you can consult the help for the functions that come with the package as well as the package’s vignettes.

Once you installed a package, you have to load it before you can use it. To load packages you use the library() function:

If you only need to use one single function once, you don’t need to load an entire package. You can write the following:

using the :: operator, you can access functions from packages without having to load the whole package beforehand.

It is possible and easy to create your own packages. This is useful if you have to write a lot of functions that you use daily. We will lean about that, in Chapter 10.