tar_eval_raw {tarchetypes} | R Documentation |
Evaluate multiple expressions created with symbol substitution (raw version).
Description
Loop over a grid of values, create an expression object
from each one, and then evaluate that expression.
Helps with general metaprogramming. Unlike tar_sub()
,
which quotes the expr
argument, tar_sub_raw()
assumes expr
is an expression object.
Usage
tar_eval_raw(expr, values, envir = parent.frame())
Arguments
expr |
Expression object with the starting expression.
Values are iteratively substituted
in place of symbols in |
values |
List of values to substitute into |
envir |
Environment in which to evaluate the new expressions. |
Value
A list of return values from evaluating the expression objects. Often, these values are target objects. See the "Target objects" section for background on target objects specifically.
Target objects
Most tarchetypes
functions are target factories,
which means they return target objects
or lists of target objects.
Target objects represent skippable steps of the analysis pipeline
as described at https://books.ropensci.org/targets/.
Please read the walkthrough at
https://books.ropensci.org/targets/walkthrough.html
to understand the role of target objects in analysis pipelines.
For developers, https://wlandau.github.io/targetopia/contributing.html#target-factories explains target factories (functions like this one which generate targets) and the design specification at https://books.ropensci.org/targets-design/ details the structure and composition of target objects.
See Also
Other Metaprogramming utilities:
tar_eval()
,
tar_sub()
,
tar_sub_raw()
Examples
# tar_map() is incompatible with tar_render() because the latter
# operates on preexisting tar_target() objects. By contrast,
# tar_eval_raw() and tar_sub_raw() iterate over code farther upstream.
values <- list(
name = lapply(c("name1", "name2"), as.symbol),
file = c("file1.Rmd", "file2.Rmd")
)
tar_sub_raw(quote(list(name, file)), values = values)
tar_sub_raw(quote(tar_render(name, file)), values = values)
path <- tempfile()
file.create(path)
str(tar_eval_raw(quote(tar_render(name, path)), values = values))
# So in your _targets.R file, you can define a pipeline like as below.
# Just make sure to set a unique name for each target
# (which tar_map() does automatically).
values <- list(
name = lapply(c("name1", "name2"), as.symbol),
file = c(path, path)
)
list(
tar_eval_raw(quote(tar_render(name, file)), values = values)
)