Attempts to read a computed target from a targets pipeline using `targets::tar_read()`. If the target cannot be read (e.g., it hasn't been computed yet), runs a fallback expression instead. Useful in interactive workflows where a target may not always be available.
tar_or_run(target, expr, quiet = FALSE, store = here::here("_targets"), ...)Unquoted name of the target to read (not a string).
Expression to evaluate if target read fails. Will be evaluated lazily only if needed.
Logical. If `FALSE` (default), print messages explaining why the target read failed and that the fallback is running. If `TRUE`, suppress these messages.
Character path to the targets store. Defaults to `here::here("_targets")`.
Additional arguments passed to `targets::tar_read()` (except `store`).
The value of the read target if successful, otherwise the result of evaluating `expr`.
if (FALSE) { # \dontrun{
# Try to read a computed target, fall back to a simple value
tar_or_run(my_data, data.frame(x = 1:5))
# Suppress messages when using interactively
tar_or_run(results, compute_results(), quiet = TRUE)
} # }