library(readxl)
library(writexl)
library(quanteda)
library(lattice)
library(tidyverse)
library(crosstable)
library(flextable)
library(confintr)
9 Libraries
9.1 Recommended reading
Winter (2020): Chapter 1.13
9.2 Working with packages in R
Packages expand the basic functionality of R by providing numerous quality-of-life improvements that not only considerably simplify common data wrangling tasks but which also provide frameworks for state-of-the-art methods for statistical analysis and natural language processing (NLP), among many other things.
9.2.1 Installation
Navigate to Packages
> Install
and verify that the pop-up window says Install from: Repository (CRAN)
. You can now type in the name of the package you would like to install under Packages
.
This reader will use functions from a variety of R packages. Please install the following ones:
Package | Purpose | Session |
---|---|---|
readxl |
Importing Microsoft Excel files | Importing/exporting |
writexl |
Exporting Microsoft Excel files | Importing/exporting |
quanteda |
Analysis of text data | Concordancing |
lattice |
Data visualisation | Concordancing |
tidyverse |
Framework for data manipulation and visualisation | Categorical data, Continuous data |
crosstable |
Creating contingency tables | Categorical data |
flextable |
Exporting contingency tables | Categorical data |
confintr |
Effect size measure for categorical data | Chi-squared test |
9.2.2 Loading packages
Once the installation has been completed, you can proceed to load the libraries using the code below. You can ignore the warning messages.
Whenever you start a new R session (i.e., open RStudio), your libraries and their respective functions will be inactive. To re-activate a library, either use the library()
function or simply select it in the Packages
tab.
It is good practice to only activate those packages that are necessary for your analysis. While it won’t be a problem for the small set of packages as shown here, loading dozens of packages increases the risk of obtaining “homonymous” functions which have the same name but perform different operations. In this case, it might be helpful to “disambiguate” them by directly indicating which package a function is from:
::read_xlsx(...) readxl
9.2.3 Citing R and R packages
Whenever we draw on ideas other than our own, we give credit to the respective source by citing it appropriately. The same applies to R, RStudio as well as all the packages we rely on throughout our analyses.
For R, an up-to-date citation can be generated as follows:
citation()
To cite R in publications use:
R Core Team (2023). R: A language and environment for statistical
computing. R Foundation for Statistical Computing, Vienna, Austria.
URL https://www.R-project.org/.
A BibTeX entry for LaTeX users is
@Manual{,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2023},
url = {https://www.R-project.org/},
}
We have invested a lot of time and effort in creating R, please cite it
when using it for data analysis. See also 'citation("pkgname")' for
citing R packages.
To cite a specific package, simply supply the package name as an argument.
citation("quanteda")
To cite package 'quanteda' in publications use:
Benoit K, Watanabe K, Wang H, Nulty P, Obeng A, Müller S, Matsuo A
(2018). "quanteda: An R package for the quantitative analysis of
textual data." _Journal of Open Source Software_, *3*(30), 774.
doi:10.21105/joss.00774 <https://doi.org/10.21105/joss.00774>,
<https://quanteda.io>.
A BibTeX entry for LaTeX users is
@Article{,
title = {quanteda: An R package for the quantitative analysis of textual data},
journal = {Journal of Open Source Software},
author = {Kenneth Benoit and Kohei Watanabe and Haiyan Wang and Paul Nulty and Adam Obeng and Stefan Müller and Akitaka Matsuo},
doi = {10.21105/joss.00774},
url = {https://quanteda.io},
volume = {3},
number = {30},
pages = {774},
year = {2018},
}