DRDataRaft/ docs
GitHub ↗

dr_as_targets()

Converts one product, or a named list of products, into ordinary targets targets. Nested product sources become explicit upstream dependencies. File sources get separate format = "file" targets so changes invalidate downstream products. Constructing the graph never runs a product.

Usage

dr_as_targets(x, cue = NULL, evidence = NULL)

Arguments

x
Table product or named list of table products. Nested products are included. Schedule a complete model publication with targets::tar_target().


cue
Optional targets::tar_cue() applied to product targets.


evidence
Optional directory for dataraft.core::dr_run() evidence.

Value

A list of objects from targets::tar_target_raw(). Product target names are derived from product IDs with make.names(); conflicting names are rejected. Collect a stored result with dataraft.core::dr_collect(targets::tar_read(id)).

Details

Place dr_as_targets(...) at the end of _targets.R, then use targets::tar_make(). targets owns caching, dependency scheduling and parallelism. Each product is run once in the graph; downstream products use its completed output. Product IDs must identify one definition throughout the graph.

Only local file changes are inferred automatically. For APIs, databases and other externally changing sources, provide an appropriate cue, commonly targets::tar_cue(mode = "always"). Use connection factories; open DBI connections and lazy tables cannot be safely stored in a targets cache. A cached product does not create new run evidence until it executes again. Function bodies and captured values are part of the embedded specification; source project code from _targets.R to rebuild definitions when it changes. Static references to ordinary captured values are tracked. Dynamic lookups and mutable environment state need an explicit cue, just like remote data. Give definition variables names such as orders_definition when the target is named orders, to avoid targets' global-object name collision warning.

Examples

\dontshow{if (requireNamespace("targets", quietly = TRUE)) withAutoprint(\{ # examplesIf}
orders <- dataraft.core::dr_product("orders") |> dataraft.core::dr_add_source(data.frame(id = 1:2))
dr_as_targets(orders)
\dontshow{\}) # examplesIf}

See also

dr_init_project(), dataraft.core::dr_run()
Documentation source snapshot · View source at 2f9432d ↗
Code examples are documented source examples; they are not executed in this website build.

Search documentation

Search functions, packages and guides.