From 975a7f0ed320c747917aae0e31999cf3e2376491 Mon Sep 17 00:00:00 2001 From: wlandau Date: Fri, 8 Nov 2024 14:11:09 -0500 Subject: [PATCH] produce buds differently --- R/class_stem.R | 13 ++++++++----- tests/testthat/test-class_stem.R | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/R/class_stem.R b/R/class_stem.R index a9109013..5083808e 100644 --- a/R/class_stem.R +++ b/R/class_stem.R @@ -166,14 +166,17 @@ stem_tar_assert_nonempty <- function(target) { } } -stem_produce_buds <- function(target) { - settings <- target$settings - names <- target_get_children(target) - map(seq_along(names), ~bud_new(names[.x], settings, .x)) +stem_produce_bud <- function(target, name) { + junction <- .subset2(target, "junction") + index <- junction_extract_index(junction, name) + bud_new(name = name, settings = .subset2(target, "settings"), index = index) } stem_insert_buds <- function(target, pipeline) { - map(stem_produce_buds(target), pipeline_set_target, pipeline = pipeline) + map( + junction_splits(target$junction), + ~pipeline_set_target(pipeline, stem_produce_bud(target, .x)) + ) } stem_ensure_buds <- function(target, pipeline, scheduler) { diff --git a/tests/testthat/test-class_stem.R b/tests/testthat/test-class_stem.R index 9b3b0282..cdce95d1 100644 --- a/tests/testthat/test-class_stem.R +++ b/tests/testthat/test-class_stem.R @@ -29,13 +29,13 @@ tar_test("stem$update_junction() on a good stem", { expect_true(all(grepl("abc_", out))) }) -tar_test("stem_produce_buds()", { +tar_test("stem produce buds", { x <- target_init(name = "abc", expr = quote(letters)) tar_option_set(envir = baseenv()) target_run(x, tar_option_get("envir"), path_store_default()) pipeline <- pipeline_init(list(x)) stem_update_junction(x, pipeline) - children <- stem_produce_buds(x) + children <- map(target_get_children(x), ~stem_produce_bud(x, .x)) expect_true(is.list(children)) expect_length(children, length(letters)) for (index in seq_along(letters)) {