selectively using statically generated branches #324
-
hi - I'm using tar_map to generate a bunch of different variations of data and I'd like to selectively use some of those generated targets in downstream operations. For instance, take a historical data pull (that is currently one target) and another data pull and build a model on the historical bit and test on another dataset. So basically generating a bunch of different targets and branches with tar_map (and even dynamic branching within tar_map) and then do dynamic branching over targets that span a few independent branches in a following tar_target call. But I'm having trouble figuring out how to reference the targets and create a target vector that can be dynamically mapped over. What I think I'd like to do is use a regex pattern in the pattern = field for tar_target and then map over the targets that fit that criteria. Is that possible or is there an example that might do this? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Something like this for instance - tar_target(some_models, fit_model(starts_with("historical")), pattern = map(starts_with("historical"))) |
Beta Was this translation helpful? Give feedback.
-
If you want to select some dynamic branches just for testing purposes initially, then the alternative patterns at https://books.ropensci.org/targets/dynamic.html#pattern-construction like library(targets)
tar_script({
library(tarchetypes)
first_targets <- tar_map(tar_target(first, f(x)), values = list(x = letters[1:5]))
selected_first_targets <- rlang::syms(c("first_a", "first_d"))
downstream_targets <- tar_map(
tar_target(downstream, g(x)),
values = list(x = selected_first_targets)
)
list(first_targets, downstream_targets)
})
tar_glimpse() Created on 2021-02-25 by the reprex package (v1.0.0) |
Beta Was this translation helpful? Give feedback.
If you want to select some dynamic branches just for testing purposes initially, then the alternative patterns at https://books.ropensci.org/targets/dynamic.html#pattern-construction like
head()
orsample()
might help. For static branching, you can first generate some target objects withtar_map()
ortar_eval()
, check the names, and then mention them in downstream commands. Another round oftar_eval()
ortar_map()
can select the targets you need.