2.18 Packages and Libraries

REVIEW The power of the R ecosystem comes from the ability to extend the language by its nature as open source software. Anyone is able to contribute to the R ecosystem and by following stringent guidelines they can have their contributions included in the comprehensive R archive network, abbreviated as CRAN. Such contributions are collected by an author into what is called a package. Over the decades many researchers and developers have contributed very many packages to CRAN.

A package is how R collects together commands for a specific collection of tasks. A command is a verb in the computer language used to tell the computer to do something. There are over 21,000 packages available for R from almost as many different authors. Hence there are very many verbs available to build our sentences to command R appropriately. With so many packages there is bound to be a package or two covering essentially any kind of processing we could imagine though we will also find packages offering the same or similar commands (verbs) perhaps even with very different meanings.

Most chapters will list at the beginning of the chapter the R packages that are required for us to be able to replicate the examples presented in that chapter. Packages are installed from the Internet (from the securely managed CRAN package repository) into a local library on our own computer. A library is a folder on our computer’s storage which contains sub-folders corresponding to each of the installed packages.

To install a package from the Internet we can use the command install.packages() and provide to it as an argument the name of the package to install. The package name is provided as a string of characters within quotes and supplied as the pkgs= argument to the command as in the following code. Here we choose to install a package called dplyr—a very useful package for data manipulations.

# Install a package from a CRAN repository.

install.packages(pkgs="dplyr")

Once a package is installed we can access the commands provided by that package by prefixing the command name with the package name as in ggplot2::qplot(). This is to say that qplot() is provided by the ggplot2 (Wickham et al. 2024) package.

References

Wickham, Hadley, Winston Chang, Lionel Henry, Thomas Lin Pedersen, Kohske Takahashi, Claus Wilke, Kara Woo, Hiroaki Yutani, Dewey Dunnington, and Teun van den Brand. 2024. Ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics. https://ggplot2.tidyverse.org.


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0