targets
https://papsti.github.io/talks/2023-10-19_targets.html
Pipelining is the process of writing down a recipe for outputs where all dependencies are stated explicitly.
library(readr); library(dplyr); library(ggplot2)
library(doParallel); cl <- makeCluster(4); registerDoParallel(cl)
# read & clean data
data = (read_csv("data/case-counts.csv")
|> filter(date >= "2023-01-01")
)
# specify parameters
foreach(scenario = c("A", "B", "C")) %dopar% {
# simulate
sim = make_forecast(
data,
scenario = scenario
)
# plot results
plot_forecast(sim)
}
targets
“The
targets
package is a Make-like pipeline tool for statistics and data science in R.”– the
targets
user manual
In a government and/or corporate setting, an R package can be easier
renv
<3)_targets.R
filelibrary(targets)
source("R/make_forecast.R"); source("R/plot_forecast.R")
tar_option_set(packages = c("readr", "dplyr", "ggplot2", "lubridate"))
# pipeline
list(
# read & clean data
tar_target(
data,
(read_csv("data/case-counts.csv")
|> filter(date >= "2023-01-01")
)
),
# simulate
tar_target(
sim,
make_forecast(data)
),
# plot results
tar_target(
plot,
plot_forecast(sim)
)
)
crew
tarchetypes
: target archetypes for common tasks✔ skip target data
▶ start target sim
✖ error target sim
▶ end pipeline [0.278 seconds]
Error:
! Error running targets::tar_make()
Error messages: targets::tar_meta(fields = error, complete_only = TRUE)
Debugging guide: https://books.ropensci.org/targets/debugging.html
How to ask for help: https://books.ropensci.org/targets/help.html
Last error: object 'x' not found
Don’t do this!
sim_ON
)sim_3e0e0255
)targets
pipelines (and R packages)
R/
roxygen
targets
user manual!targets
user manual!crew
and tarchetypes
to go furtherhttps://papsti.github.io/talks/2023-10-19_targets.html