tar_target_path: Track a script argument as a 'targets' dependency

View source: R/utils.R

tar_target_pathR Documentation

Track a script argument as a targets dependency

Description

Use as the script, pre_script, or post_script argument of tar_target_py()/tar_target_jl()/tar_target_rs() (and their ⁠_raw⁠ forms) instead of a literal path string, to make that step re-run whenever the script file changes. name is the name of an upstream targets target (typically one created with format = "file" tracking the script file), and its value (the file path) is substituted in when the pipeline runs.

Usage

tar_target_path(name)

Arguments

name

Character string, the name of an upstream target whose value is the script's file path (e.g. a tar_target(..., format = "file")).

Details

This mirrors how inputs = c(x = "some_target") already wires an upstream target in by name: the target's name is given as a string, and the constructor turns it into a real dependency. A plain string passed directly as script/pre_script/post_script keeps meaning what it always has (an untracked literal path), so existing pipelines are unaffected.

Value

An object marking name for dependency-wiring by the ⁠tar_target_*⁠ constructors.

See Also

tar_target_py(), tar_target_jl(), tar_target_rs()

Examples

# Building a target does not run it, so this example needs no Python.
# python/fit_step.py:
#   result = sum(x)
# scripts/pre.R:
#   to_py <- list(x = x)
list(
  targets::tar_target(fit_pyscript, "python/fit_step.py", format = "file"),
  tar_target_py(
    name = fit,
    script = tar_target_path("fit_pyscript"),  # re-runs when the file changes
    pre_script = "scripts/pre.R",              # untracked literal path
    inputs = c(x = "prepared_x"),
    retrieve = "result"
  )
)

tarpolyglot documentation built on Nov. 22, 2026, 5:07 p.m.