
Why care about workflows?
How {targets} works
Hand-on {targets} practice!
Andrew Heiss
Assistant professor of public policy, Georgia State University
Data visualization, statistics, and causal inference

All the materials for today are accessible at

Statistical research
is a complicated,
messy process!
Each of these come
from different places!
Each of these can be
in a different state!
Put everything in one document
.docx fileEmbrace the bittiness and compile it all at the end
Mentally remember to run all the scripts when data changes, replace old figures/tables/values with new values, and manually run everything in the right order.
Carefully document the precise order that your scripts run, maybe even with a master script that runs everything for you. Run the master script when data changes and rebuild the whole thing every time. Maybe get fancy with things like Quarto caching/freezing.
Divide workflow into separate objects and let software keep track of which things are out of date and orchestrate which things need to re-run. Run one command to rebuild the whole project, skipping dependencies that don’t need to build again.
01_clean.R + 02_analysis.R + 03_plots.R
R Markdown/Quarto websites (example)
01_clean.Rmd + 02_analysis.Rmd + 03_plots.Rmd + caching

There’s a whole Quarto book with detailed documentation
tar_make()
tar_load(target_name) or blah <- tar_read(target_name)_targets.R_targets.R
library(targets)
# General pipeline settings
# ---------------------------
tar_option_set(
packages = c("tibble") # Packages that your targets need for their tasks.
)
# Load functions
# ----------------
# Run the R scripts in the R/ folder with your custom functions:
tar_source()
# Actual pipeline
# -----------------
list(
tar_target(
name = data, # Conceptually the same as saying `data <- tibble(...)`
command = tibble(x = rnorm(100), y = rnorm(100))
),
tar_target(
name = model, # Concetpually the same as saying `model <- coefficients(...)`
command = coefficients(lm(y ~ x, data = data))
)
)Build the whole pipeline:
In a different R script or Quarto file:
{targets} stores each target as an extension-less .rds file in _targets/objects:


