Write a helper R script for a targets pipeline.
Could be supporting functions or the target script file
(default: _targets.R) itself.
tar_helper() expects an unevaluated expression for the code
argument, whereas tar_helper_raw() expects an evaluated
expression object.
Usage
tar_helper(path = NULL, code = NULL, tidy_eval = TRUE, envir = parent.frame())
tar_helper_raw(path = NULL, code = NULL)Arguments
- path
Character of length 1, path to write (or overwrite)
code. If the parent directory does not exist,tar_helper_raw()creates it.tar_helper()overwrites the file if it already exists.- code
Code to write to
path.tar_helper()expects an unevaluated expression for thecodeargument, whereastar_helper_raw()expects an evaluated expression object.- tidy_eval
Logical, whether to use tidy evaluation on
code. If turned on, you can substitute expressions and symbols using!!and!!!. See examples below.- envir
Environment for tidy evaluation.
Details
tar_helper() is a specialized version of tar_script()
with flexible paths and tidy evaluation.
See also
Other scripts:
tar_edit(),
tar_github_actions(),
tar_renv(),
tar_script()
Examples
# Without tidy evaluation:
path <- tempfile()
tar_helper(path, code = x <- 1)
tar_helper_raw(path, code = quote(x <- 1)) # equivalent
writeLines(readLines(path))
#> x <- 1
# With tidy evaluation:
y <- 123
tar_helper(path, x <- !!y)
writeLines(readLines(path))
#> x <- 123