Chapter 8 Packages

Packages are user-provided extensions to the basic R system (comparable to an “add-on” or “extension” for some web browsers). Packages may contain custom datasets, additional functions, re-formulations of existing functions, and more. There are by now thousands of useful packages extending R.

A package named ABC can be installed by entering install.packages("ABC") (with double quotes) and then require(ABC) (without double quotes). If a package in turn requires other packages, these are also installed and loaded.

Some useful packages are the following:

  • datasets: A wide variety of datasets, for exploration and education. This package is now integrated within R (see Help on datasets).

  • foreign: Functions for reading and writing data stored by statistical packages such as Minitab, S, SAS, SPSS, Stata, Systat, and for reading CSV files (comma separated values) created by Microsoft Excel, and for reading and writing dBase files (R Core Team 2022).

  • lattice: Trellis graphics for R. The functions provide a powerful, elegant and flexible high-level data visualization system, using Trellis graphics, with an emphasis on multivariate data (Sarkar 2021).

  • MASS: Datasets and functions accompanying (Venables and Ripley 2002; Ripley 2022)

  • languageR: Datasets and functions accompanying (Baayen 2008; Baayen and Shafaei-Bajestan 2019).

  • hqmisc: Some convenience functions and an example dataset, by the present author (Quené 2014), and used in this booklet.

  • tidyverse: A meta-package consisting of many other packages supporting your data science, such as dplyr for data transformation, ggplot2 for data visualization, and rmarkdown for reporting (also used for this booklet) (Wickham et al. 2019); all component packages can also be used separately.

Packages are stored on a so-called repository; the CRAN repository is the most important one (https://cran.r-project.org/). You should use a nearby mirror site of the CRAN repository, by giving the command chooseCRANmirror(). Rstudio and R remember your chosen mirror site over multiple sessions.

Finally, to inspect the status of your current session in R, use the command sessionInfo(). This will return a listing of technical information, locale settings, all attached packages, and all loaded packages, with version info for each.

References

Baayen, R. H. 2008. Analyzing Linguistic Data: A Practical Introduction to Statistics Using R. Cambridge University Press.
Baayen, R. H., and Elnaz Shafaei-Bajestan. 2019. languageR: Analyzing Linguistic Data: A Practical Introduction to Statistics. https://CRAN.R-project.org/package=languageR.
———. 2014. Hqmisc: Miscellaneous Convenience Functions and Dataset. https://CRAN.R-project.org/package=hqmisc.
R Core Team. 2022. Foreign: Read Data Stored by Minitab, s, SAS, SPSS, Stata, Systat, Weka, dBase, ... https://svn.r-project.org/R-packages/trunk/foreign/.
Ripley, Brian. 2022. MASS: Support Functions and Datasets for Venables and Ripley’s MASS. http://www.stats.ox.ac.uk/pub/MASS4/.
Sarkar, Deepayan. 2021. Lattice: Trellis Graphics for r. http://lattice.r-forge.r-project.org/.
Venables, W. N., and B. D. Ripley. 2002. Modern Applied Statistics with s. 4th ed. Springer.
Wickham, Hadley, Mara Averick, Jennifer Bryan, Winston Chang, Lucy D’Agostino McGowan, Romain François, Garrett Grolemund, et al. 2019. “Welcome to the tidyverse.” Journal of Open Source Software 4 (43): 1686. https://doi.org/10.21105/joss.01686.