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 2020).

  • 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 2018).

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

  • 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.

Quené, Hugo. 2014. Hqmisc: Miscellaneous Convenience Functions and Dataset. https://CRAN.R-project.org/package=hqmisc.

R Core Team. 2020. Foreign: Read Data Stored by ’Minitab’, ’S’, ’Sas’, ’Spss’, ’Stata’, ’Systat’, ’Weka’, ’dBase’, ... https://CRAN.R-project.org/package=foreign.

Ripley, Brian. 2019. MASS: Support Functions and Datasets for Venables and Ripley’s Mass. https://CRAN.R-project.org/package=MASS.

Sarkar, Deepayan. 2018. Lattice: Trellis Graphics for R. https://CRAN.R-project.org/package=lattice.

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.