Literate, linear programming
Humboldt-Universität zu Berlin
2024-05-14
how you write your code is the first step in making it reproducible
the first principle is that your code must be linear
introduced in 1992 by Donald Knuth (Knuth, 1984)
refers to writing and documenting our code so that humans can understand it
we need to not only know what our code is doing when we look back at it in the future/share it
the easiest way: informative comments
# Analysis script for phoneme paper
# author: Joe DiMaggio
# date: Feb. 29, 2024
# purpose: analyse cleaned dataset
# Set-up ###
# load required packages
library(dplyr)
library(readr)
library(ggplot2)
library(lme4)
library(broom.mixed) # tidy model summaries
library(ggeffects) # model predictions
library(here) # project-relative file path
# load-in data
df_phon <- read_csv(here("data", "phoneme_tidy_data.csv"))
# Explore data ###
###
)
.Rmd
file extension) and Quarto (.qmd
) are extensions of markdown
describe the function/purpose at the beginning
document your train of thought and findings throughout the script
give an overview of the findings/end result at the end
it’s wise to avoid very long, multi-purpose scripts
dplyr
version 1.1.0
or later, which introduced the .by
per-operation grouping argumentdplyr
tries to run your code?
R version 4.4.0 (2024-04-24)
Platform: aarch64-apple-darwin20
Running under: macOS Ventura 13.2.1
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
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] compiler_4.4.0 fastmap_1.2.0 cli_3.6.2 htmltools_0.5.8.1
[5] tools_4.4.0 rstudioapi_0.16.0 yaml_2.3.8 rmarkdown_2.27
[9] knitr_1.47 jsonlite_1.8.8 xfun_0.44 digest_0.6.35
[13] rlang_1.1.4 renv_1.0.7 evaluate_0.23