最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

metaprogramming - Nested targets static branching loops (tar_map) in R with dependency from one iteration to the next - Stack Ov

programmeradmin1浏览0评论

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?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论