Coding and Teaching Library

Last updated on

March 4, 2026

Information
This is the new repository for my coding and teaching materials. I gradually transfer them from my github page to this Quarto book.

Preface

This book serves as a library for my coding and teaching materials that I have developed over the years. The material is based on textbooks (references will be provided), websites (stackexchange, stackoverflow, …), and various online resources (e.g., blogs, books). Since AI tools have taken over coding, all my code is written and reviewed with the help of AI tools (see the transparency statement below).

NoteTransparency statement regarding the use of AI tools

The updated version of this library was written with the help of AI tools (ChatGPT 5, GitHub Copilot). All AI-generated text was carefully reviewed and edited by the author. Any errors or inaccuracies are the author’s own.

Leading Principles

Mainly caused through the replication/reproducibility crisis and my growing interest in reproducible coding practices, I try to follow two principles when writing code or teaching methods:

  1. Computational Reproducibility: Most of the time, I strive to make all code and analyses reproducible. This means that anyone should be able to run the code and obtain the same results, regardless of their computing environment.

  2. Transparency: Secondly, I try to be as transparent as possible about the methods and tools I use. This means providing clear documentation (and explanations) for the majority of code and analyses.

Software

Most of the provided code is from the statistical software R (R Core Team, 2025). You will also find some Quarto, yaml code snippets.

R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
 [1] htmlwidgets_1.6.4 compiler_4.5.2    fastmap_1.2.0     cli_3.6.5        
 [5] htmltools_0.5.9   tools_4.5.2       otel_0.2.0        yaml_2.3.12      
 [9] rmarkdown_2.30    knitr_1.51        jsonlite_2.0.0    xfun_0.56        
[13] digest_0.6.39     rlang_1.1.7       renv_1.1.7        evaluate_1.0.5   

(Most Actively) Used Packages

The following (character) vector lists the R packages that I constantly use. The list may not be exhaustive, but it includes the most important ones.

pkg_list <- c(
  # Reproducibility & Project Infrastructure
  "here",        # file paths
  "renv",        # dependency management
  "pak",         # package management
  "knitr",       # dynamic report engine
  
  # Development
  "devtools",    # package development
  
  # Data Handling
  "haven",       # SPSS/Stata import
  "stringr",     # string handling
  
  # Statistical Modeling
  "lme4",        # linear mixed models
  "lavaan",      # SEM
  
  # Report & Visualization
  "DT",          # interactive tables
  "ggplot2"      # graphics
)

In the following you find the version of the packages which the book depends on. There complete list of all packages (including dependencies) that are used. The list is generated based on the renv lockfile.

Package Documentation

Code
pkg_dfs <- helpmecode::renv_lock_to_df()

pkg_dfs[pkg_dfs$package %in% pkg_list,] |> 
    DT::datatable(rownames = FALSE)

The renv_lock_to_df() function of the helpmecode package processes the lockfile accordingly and returns a data frame with 3 columns: package, version, and source. The helpmecode package is an internal package that encompasses a variety of helper functions when working with R.

Credit to the Package Developers

Code
for (i in seq_along(pkg_list)) {
  paste0("`",pkg_list[i],"`", " [@R-", pkg_list[i], "], ") |> 
    cat()
}

here (Müller, 2025), renv (Ushey & Wickham, 2026), pak (Csárdi & Hester, 2025), knitr (Xie, 2025), devtools (Wickham, Hester, et al., 2025), haven (Wickham, Miller, et al., 2025), stringr (Wickham, 2025), lme4 (Bates et al., 2025), lavaan (Rosseel et al., 2025), DT (Xie et al., 2025), ggplot2 (Wickham et al., 2026),

Package Installation

If you are interested in using the same packages as in this book, you can install them by running the following code snippets. To do this, I recommend using the pak package (Csárdi & Hester, 2025). The pak package is desinged to overcome some limitations of the install.packages() function and makes package management in R more reliable.

install.packages("pak", dependencies = TRUE)

Once the pak package is installed, you can install the packages by running one of the following code snippets.

Code
inst_pkg_version <- pkg_dfs[pkg_dfs$package %in% pkg_list,]
paste0("pkgs_with_version <- c(",
    paste0("'", with(inst_pkg_version, paste0(package, "@", version)), "'",
           collapse = ", "),
    ")") |>
      stringr::str_wrap(width = 60) |>
      cat()
pkgs_with_version <- c('DT@0.34.0', 'ggplot2@4.0.2',
'here@1.0.2', 'knitr@1.51', 'lavaan@0.6-21', 'lme4@1.1-38',
'pak@0.9.2', 'renv@1.1.7', 'stringr@1.6.0')
pak::pkg_install(pkg = pkgs_with_version, upgrade = FALSE)
pak::pkg_install(pkg = pkg_list, upgrade = TRUE)

License & Disclaimer

Unless noted otherwise, the content (text, figures, descriptions, etc.) of the website is licensed under CC BY 4.0.

You are free to:

Share — copy and redistribute the material in any medium or format for any purpose, even commercially.

Adapt — remix, transform, and build upon the material for any purpose, even commercially.

The licensor cannot revoke these freedoms as long as you follow the license terms.

Under the following terms:

Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Notices:

You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.

No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.

Code is released under the MIT License.

Copyright (c) 2024–2026 Sven Rieger

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Third-party components remain under their respective licenses. You are responsible for complying with those licenses.

No warranty is given regarding correctness, completeness, or availability.

Bugs & Errors

Found errors or any bugs? Please send me an email or report them directly to github.com. At every page, below the table of contents, there is link to the repository of the website. If you think your issue may important for others, please use this option.