| Title: | Economic Policy Institute tools for working with targets |
|---|---|
| Description: | Additional utilities to use the targets R package. |
| Authors: | Ben Zipperer [aut, cre], Economic Policy Institute [cph, fnd] |
| Maintainer: | Ben Zipperer <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-05-24 06:03:17 UTC |
| Source: | https://github.com/economic/epitargets |
Gathers the values of companion _date targets (created by
tar_target_date() or tar_age_date()) into a tibble::tibble with columns
name and time.
collect_target_date(...)collect_target_date(...)
... |
Date values from |
A tibble::tibble with columns name (character) and time.
collect_target_date(x_date = as.Date("2024-01-01"), y_date = as.Date("2024-06-15"))collect_target_date(x_date = as.Date("2024-01-01"), y_date = as.Date("2024-06-15"))
A thin wrapper around readr::write_csv() that writes data to file and
returns the file path. This is useful as a targets format function where the
target value should be the path to the written file.
create_csv(data, file, ...)create_csv(data, file, ...)
data |
A data frame to write. |
file |
A string giving the file path to write to. |
... |
Additional arguments passed to |
The file path file, invisibly.
targets::tar_dir({ create_csv(data.frame(x = 1:3), "test.csv") })targets::tar_dir({ create_csv(data.frame(x = 1:3), "test.csv") })
Like tar_target_date() but adds an age-based cue via
tarchetypes::tar_cue_age_raw() so the target automatically re-runs after
a configurable time period. Useful for targets that fetch data from APIs.
tar_age_date(name, command, age = as.difftime(1, units = "days"), ...)tar_age_date(name, command, age = as.difftime(1, units = "days"), ...)
name |
Symbol, name of the target. |
command |
Expression, R command to run the target. |
age |
A difftime object specifying the maximum age before the target re-runs. Defaults to 1 day. |
... |
Additional arguments passed to |
A list of two target objects: the primary target (with an age cue)
and the companion _date target.
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_age_date(x, 1 + 1, age = as.difftime(1, units = "days")) ) }) targets::tar_make() targets::tar_read(x) targets::tar_read(x_date) }) }if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_age_date(x, 1 + 1, age = as.difftime(1, units = "days")) ) }) targets::tar_make() targets::tar_read(x) targets::tar_read(x_date) }) }
A convenience wrapper around tarchetypes::tar_file_read() for CSV files.
Creates a pair of targets: one to track the file with format = "file",
and another to read the file with readr::read_csv().
tar_csv_read(name, command, .read_csv_args = list(show_col_types = FALSE), ...)tar_csv_read(name, command, .read_csv_args = list(show_col_types = FALSE), ...)
name |
Symbol, name of the target. |
command |
Expression, R code that returns the file path to the CSV. |
.read_csv_args |
A named list of additional arguments passed to
|
... |
Additional arguments passed to |
The storage format of the read target is inherited from
targets::tar_option_get("format") (by default "rds"). Callers can
override it by passing e.g. format = "qs" via ....
A list of two target objects: a file-tracking target
(name_file) and a CSV-reading target (name).
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_csv_read(my_data, "data.csv") ) }) targets::tar_manifest() }) }if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_csv_read(my_data, "data.csv") ) }) targets::tar_manifest() }) }
A convenience wrapper around tarchetypes::tar_file_read() for Parquet
files. Creates a pair of targets: one to track the file with
format = "file", and another to read the file with arrow::read_parquet().
tar_parquet_read(name, command, .read_parquet_args, ...)tar_parquet_read(name, command, .read_parquet_args, ...)
name |
Symbol, name of the target. |
command |
Expression, R code that returns the file path to the Parquet file. |
.read_parquet_args |
A named list of additional arguments passed to
|
... |
Additional arguments passed to |
The read target's storage format defaults to "parquet" (overriding
the usual targets::tar_option_get("format") inheritance), so the cached
object is written as a Parquet file in _targets/objects/. Callers can
override this by passing e.g. format = "rds" via ....
A list of two target objects: a file-tracking target
(name_file) and a Parquet-reading target (name).
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_parquet_read(my_data, "data.parquet") ) }) targets::tar_manifest() }) }if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_parquet_read(my_data, "data.parquet") ) }) targets::tar_manifest() }) }
Wraps targets::tar_target_raw() to create a primary target and a companion
_date target that records Sys.Date() whenever the primary target runs.
tar_target_date(name, command, ...)tar_target_date(name, command, ...)
name |
Symbol, name of the target. |
command |
Expression, R command to run the target. |
... |
Additional arguments passed to |
A list of two target objects: the primary target and the companion
_date target.
if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_target_date(x, 1 + 1) ) }) targets::tar_make() targets::tar_read(x) targets::tar_read(x_date) }) }if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { targets::tar_dir({ targets::tar_script({ library(targets) list( epitargets::tar_target_date(x, 1 + 1) ) }) targets::tar_make() targets::tar_read(x) targets::tar_read(x_date) }) }