diff --git a/R/class_junction.R b/R/class_junction.R index d615604a..1d8f5f4f 100644 --- a/R/class_junction.R +++ b/R/class_junction.R @@ -3,32 +3,33 @@ junction_init <- function( splits = character(0), deps = list() ) { - splits <- make.unique(splits, sep = "_") + index <- seq_along(splits) + names(index) <- make.unique(splits, sep = "_") names(deps) <- names(deps) %|||% seq_along(deps) deps <- as_data_frame(deps) - junction_new(nexus, splits, deps) + junction_new(nexus, index, deps) } -junction_new <- function(nexus = NULL, splits = NULL, deps = NULL) { +junction_new <- function(nexus = NULL, index = NULL, deps = NULL) { out <- new.env(parent = emptyenv(), hash = FALSE) out$nexus <- nexus - out$splits <- splits + out$index <- index out$deps <- deps out } junction_upstream_edges <- function(junction) { from <- utils::stack(junction$deps)$values - to <- rep(junction$splits, times = ncol(junction$deps)) + to <- rep(junction_splits(junction), times = ncol(junction$deps)) data_frame(from = from, to = to) } junction_splits <- function(junction) { - as.character(junction$splits) + names(junction$index) } junction_transpose <- function(junction) { - splits <- junction$splits + splits <- junction_splits(junction) deps <- junction$deps out <- map_rows(deps, ~list(deps = unname(.x))) %||% replicate(length(splits), list(deps = character(0)), simplify = FALSE) @@ -39,7 +40,7 @@ junction_transpose <- function(junction) { } junction_invalidate <- function(junction) { - junction$splits <- rep(NA_character_, length(junction$splits)) + names(junction$index) <- rep(NA_character_, length(junction$index)) } junction_validate_deps <- function(deps) { @@ -52,6 +53,7 @@ junction_validate <- function(junction) { tar_assert_correct_fields(junction, junction_new) tar_assert_scalar(junction$nexus) tar_assert_chr(junction$nexus) - tar_assert_chr(junction$splits) + tar_assert_int(junction$index) + tar_assert_chr(junction_splits(junction)) junction_validate_deps(junction$deps) } diff --git a/tests/testthat/test-class_junction.R b/tests/testthat/test-class_junction.R index b7d6699a..2ffbf40b 100644 --- a/tests/testthat/test-class_junction.R +++ b/tests/testthat/test-class_junction.R @@ -13,7 +13,7 @@ tar_test("junction_splits()", { tar_test("junction_invalidate()", { x <- junction_init("x", letters, list(a = LETTERS, b = rev(letters))) junction_invalidate(x) - expect_equal(junction_splits(x), rep(NA_character_, length(x$splits))) + expect_equal(junction_splits(x), rep(NA_character_, length(x$index))) }) tar_test("junction_upstream_edges()", { diff --git a/tests/testthat/test-class_stem.R b/tests/testthat/test-class_stem.R index 5d2afbe8..9b3b0282 100644 --- a/tests/testthat/test-class_stem.R +++ b/tests/testthat/test-class_stem.R @@ -24,7 +24,7 @@ tar_test("stem$update_junction() on a good stem", { pipeline <- pipeline_init(list(x)) stem_update_junction(x, pipeline) expect_silent(junction_validate(x$junction)) - out <- x$junction$splits + out <- junction_splits(x$junction) expect_length(out, 10L) expect_true(all(grepl("abc_", out))) })