I have a set of targets that reside within two nested static branching loops. The target x
depends on the results y
of the first cycle only when processed in the second cycle. The following pseudo-code depicts the situation. Alas, this does not run because there is a cycle in the dependencies because targets does not recognise that only the x_a_2
depend on y
. Is there a way to resolve this with as little code duplication as possible?
tar_map(values = list(a = 1:2),
tar_map(values = list(b = 1:10),
tar_target(x, if (a>1) f(a,b,y) else f(a,b,NULL))
),
),
tar_target(y, f(x_1_1, x_2_1, ..., x_10_1))
Of course, a simple solution is to roll the outer loop by hand but this involves code duplication. Is there a way to get around this duplication for the target x
in the following code snippet?
tar_map(values = list(b = 1:10),
tar_target(x_1, f(a,b,NULL))
),
tar_target(y, f(x_1_1, x_1_2, ..., x_1_10)),
tar_map(values = list(b = 1:10),
tar_target(x_2, f(a,b,y))
)
There is a different way to ask this question: Is there way to create a loop with tar_map
where the targets within each loop are processed only after the previous loop is completed?
Or to ask it in yet another way that may sound familiar to someone: Ist there a tar_fold instead of tar_map?