Introduction

The first thing we can do is run a function that will load the R packages needed for this code companion, and install them to our machine if they are not already.

packages <- c("utils", "tidyverse", "downloadthis",     # packages for data management
              "foreign", "MplusAutomation",             # packages for writing data         
              "sjPlot", "broom", "kableExtra",          # packages for generating tables
              "nlme", "lme4", "lmerTest", "stats",      # packages for MLMs
              "mgcv", "gamm4", "itsadug",               # packages for GAMMs
              "lavaan",                                 # packages for SEMs
              "ggplot2", "semPlot", "ggeffects",        # packages for visualization   
              "interactions")                           # packages for probing interactions

if (length(setdiff(packages, rownames(installed.packages()))) > 0) {
  install.packages(setdiff(packages, 
                           rownames(installed.packages())), 
                   repos = "http://cran.us.r-project.org")
}
invisible(lapply(packages, 
                 library, 
                 character.only = TRUE))

We have automatically generated a downloadable bibliography of the R package versions used in this companion for later reproducibility.

knitr::write_bib(c(
  .packages(), "bookdown", "knitr", "rmarkdown"
), "external/hitchhikers-guide-packages.bib")