Easily automate the following tasks to describe data frames: computing reliabilities (internal consistencies, retest, multilevel) for psychological scales, summarise the distributions of scales and items graphically and using descriptive statistics, combine this information with metadata (such as item labels and labelled values) that is derived from R attributes. To do so, the package relies on ‘rmarkdown’ partials, so you can generate HTML, PDF, and Word documents. Codebooks are also available as tables (CSV, Excel, etc.).
RStudio and a few of the tidyverse package already usefully display the information contained in the attributes of the variables in your data frame. The haven package also manages to grab variable documentation from SPSS or Stata files.
The codebook package takes those attributes and the data and tries to produce a good-looking codebook, i.e. a place to get an overview of the variables in a dataset. The codebook processes single items, but also “scales”, i.e. psychological questionnaires that are aggregated to extract a construct. For scales, the appropriate reliability coefficients (internal consistencies for single measurements, retest reliabilities for repeated measurements, multilevel reliability for multilevel data) are computed. For items and scales, the distributions are summarised graphically and numerically.
This package integrates tightly with formr (formr.org), an online survey framework and especially the data frames produced and marked up by the formr R package. However, codebook is completely independent of it.
Confer the help or: https://rubenarslan.github.io/codebook. See the vignette for a quick example of an HTML document generated using codebook.
If you don’t want to install the codebook package, you can just upload an annotated dataset in a variety of formats here: https://rubenarslan.ocpu.io/codebook/
Just run these two commands in R:
install.packages("devtools")
devtools::install_github("rubenarslan/codebook")To see a simple markdown document that you could use to generate a codebook, see the webapp.
The resulting codebook will be an HTML file, but you can also choose to generate PDFs or Word files.
To generate a results file in the necessary format using the formr package, you can run something like this.
library(formr)
source(".passwords.R")
formr_connect(email = credentials$email, password = credentials$password)
results = formr_results("s3_daily")
saveRDS(results, 'results.rds')To get a file in this format from SPSS, run e.g. results = haven::read_sav("path/to/file.sav")
Generating a codebook is as simple as calling codebook from a chunk in an rmarkdown document.
codebook(results)