epitargets extends the {targets} pipeline framework with automatic date-tracking and age-based cues, and other convenience functions.
install.packages(
"epitargets",
repos = c("https://economic.r-universe.dev", getOption("repos"))
)library(epitargets)tar_target_date() is a drop-in replacement for
targets::tar_target(). It creates your target plus a companion _date
target that records when it ran:
targets::tar_dir({
targets::tar_script({
library(epitargets)
list(
tar_target_date(wages, data.frame(year = 2020:2024, wage = c(15, 15, 16, 17, 18)))
)
})
targets::tar_make()
print(targets::tar_read(wages))
print(targets::tar_read(wages_date))
})
#> + wages dispatched
#> ✔ wages completed [0ms, 191 B]
#> + wages_date dispatched
#> ✔ wages_date completed [0ms, 81 B]
#> ✔ ended pipeline [124ms, 2 completed, 0 skipped]
#> year wage
#> 1 2020 15
#> 2 2021 15
#> 3 2022 16
#> 4 2023 17
#> 5 2024 18
#> [1] "2026-07-04"tar_age_date() adds an age-based cue so the target automatically
re-runs after a time period. Useful for API calls or any data that goes
stale:
targets::tar_dir({
targets::tar_script({
library(epitargets)
list(
tar_age_date(daily_data, Sys.time(), age = as.difftime(1, units = "days"))
)
})
targets::tar_make()
print(targets::tar_read(daily_data))
print(targets::tar_read(daily_data_date))
})
#> + daily_data dispatched
#> ✔ daily_data completed [0ms, 96 B]
#> + daily_data_date dispatched
#> ✔ daily_data_date completed [0ms, 81 B]
#> ✔ ended pipeline [127ms, 2 completed, 0 skipped]
#> [1] "2026-07-04 15:41:27 EDT"
#> [1] "2026-07-04"collect_target_date() gathers _date targets into a single tibble so
you can see at a glance when each target last ran:
targets::tar_dir({
targets::tar_script({
library(epitargets)
list(
tar_target_date(wages, data.frame(wage = 18)),
tar_age_date(prices, data.frame(price = 3.50)),
targets::tar_target(freshness, collect_target_date(wages_date, prices_date))
)
})
targets::tar_make()
targets::tar_read(freshness)
})
#> + prices dispatched
#> ✔ prices completed [1ms, 118 B]
#> + wages dispatched
#> ✔ wages completed [1ms, 118 B]
#> + prices_date dispatched
#> ✔ prices_date completed [0ms, 81 B]
#> + wages_date dispatched
#> ✔ wages_date completed [0ms, 81 B]
#> + freshness dispatched
#> ✔ freshness completed [2ms, 179 B]
#> ✔ ended pipeline [148ms, 5 completed, 0 skipped]
#> # A tibble: 2 × 2
#> name time
#> <chr> <date>
#> 1 wages 2026-07-04
#> 2 prices 2026-07-04tar_read_stash() reads a target and, besides returning it, leaves a
copy in the global environment as .target so you can keep exploring it
without re-running the read:
tar_read_stash(wages)
.target |> dplyr::filter(year == 2024)It really shines as an RStudio/Positron addin. Put the cursor on a
target name in _targets.R or an analysis script and trigger the
“Stash target under cursor” addin (bind it to a keyboard shortcut,
just like targets::rstudio_addin_tar_read()). The value prints to the
console and lands in .target.
The addin extracts the symbol under the cursor with
atcursor, an optional
dependency. If it isn’t installed the addin will offer to install it for
you from its r-universe repository.
