-
Help
DescriptionI'm embarking on my first heavy use of dynamic branching and want to make sure I'm not committing to an incorrect or unwise path before I get too deep. I've read through the book and discussions and there's been some useful related points but I haven't seen anything that exactly answers my question. (Apologies if I've missed something.) Basically, if I have a chain of dynamic branches, can I guarantee when I combine some later on in the pipeline that the "right" branches will always be Consider this simplified example: library(targets)
library(dplyr)
f_a_b <- function(a) {
a |> rename(x_b = x_a)
}
f_b_c <- function(b) {
b |> rename(x_c = x_b)
}
f_b_d <- function(b) {
b |> rename(x_d = x_b)
}
f_c_e <- function(c) {
c |> rename(x_e = x_c)
}
f_a_d_e <- function(a, d, e) {
a |> cross_join(d) |> cross_join(e)
}
list(
tar_target(
name = aa,
tibble(x_a = 1:5),
iteration = "vector"
),
tar_target(
name = bb,
f_a_b(aa),
pattern = map(aa)
),
tar_target(
name = cc,
f_b_c(bb),
pattern = map(bb)
),
tar_target(
name = dd,
f_b_d(bb),
pattern = map(bb)
),
tar_target(
name = ee,
f_c_e(cc),
pattern = map(cc)
),
tar_target(
name = zz,
f_a_d_e(aa, dd, ee),
pattern = map(aa, dd, ee)
)
)
tar_make()
tar_load(zz)
zz
# x_a x_d x_e
# <int> <int> <int>
# 1 1 1 1
# 2 2 2 2
# 3 3 3 3
# 4 4 4 4
# 5 5 5 5 Can I guarantee that the branches of For a bit more context, one example of this pattern is that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, you can trust the ordering you observe. In To make this clearer, |
Beta Was this translation helpful? Give feedback.
Yes, you can trust the ordering you observe. In
tar_make()
, the first branch ofzz
uses the first branch of each ofaa
,dd
, andee
. Likewise, the second branch ofzz
uses the second branch of each ofaa
,dd
, andee
, and so on.To make this clearer,
targets
could have used integer suffixes instead of hash suffixes to name branches. The specific reasons for hash suffixes are esoteric and technical, but they only have to do with decisions about rerunning vs skipping dynamic branches.