| tar_eval | R Documentation |
Loop over a grid of values, create an expression object from each one, and then evaluate that expression. Helps with general metaprogramming.
tar_eval() expects an unevaluated expression for
the expr object, whereas tar_eval_raw() expects an
evaluated expression object.
tar_eval(expr, values, envir = parent.frame())
tar_eval_raw(expr, values, envir = parent.frame())
expr |
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. |
A list of return values from the generated expression objects. Often, these values are target definition objects. See the "Target definition objects" section for background on target definition objects specifically.
Most tarchetypes functions are target factories,
which means they return target definition objects
or lists of target definition objects.
target definition 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 definition
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 definition objects.
Other Metaprogramming utilities:
tar_sub()
# tar_map() is incompatible with tar_render() because the latter
# operates on preexisting tar_target() objects. By contrast,
# tar_eval() and tar_sub() iterate over the literal code
# farther upstream.
values <- list(
name = lapply(c("name1", "name2"), as.symbol),
file = list("file1.Rmd", "file2.Rmd")
)
tar_sub(list(name, file), values = values)
tar_sub(tar_render(name, file), values = values)
path <- tempfile()
file.create(path)
str(tar_eval(tar_render(name, path), values = values))
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(tar_render(name, file), values = values)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.