Skip to content

Commit

Permalink
refactor junction a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 8, 2024
1 parent f1fd2bf commit ac7344c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions R/class_junction.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ junction_upstream_edges <- function(junction) {
data_frame(from = from, to = to)
}

junction_get_splits <- function(junction) {
as.character(junction$splits)
}

junction_transpose <- function(junction) {
splits <- junction$splits
deps <- junction$deps
Expand All @@ -34,6 +38,10 @@ junction_transpose <- function(junction) {
out
}

junction_invalidate <- function(junction) {
junction$splits <- rep(NA_character_, length(junction$splits))
}

junction_validate_deps <- function(deps) {
if (!is.null(deps) && !is.data.frame(deps)) {
tar_throw_validate("deps field of junction must be null or a data frame.")
Expand Down
3 changes: 1 addition & 2 deletions R/class_outdated.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ outdated_class <- R6::R6Class(
},
reset_junction = function(target) {
if (!is.null(target$junction)) {
new_splits <- rep(NA_character_, length(target$junction$splits))
target$junction$splits <- new_splits
junction_invalidate(target$junction)
}
},
register_checked = function(name) {
Expand Down
2 changes: 1 addition & 1 deletion R/class_pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pattern_s3_class <- c("tar_pattern", "tar_target")

#' @export
target_get_children.tar_pattern <- function(target) {
as.character(target$junction$splits)
junction_get_splits(target$junction)
}

#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/class_stem.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ target_get_children.tar_stem <- function(target) {
if_any(
is.null(target$junction),
character(0),
target$junction$splits
junction_get_splits(target$junction)
)
}

Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-class_junction.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ tar_test("junction deps", {
expect_equal(out, exp)
})

tar_test("junction_get_splits()", {
x <- junction_init("x", letters, list(a = LETTERS, b = rev(letters)))
expect_equal(junction_get_splits(x), letters)
})

tar_test("junction_invalidate()", {
x <- junction_init("x", letters, list(a = LETTERS, b = rev(letters)))
junction_invalidate(x)
expect_equal(junction_get_splits(x), rep(NA_character_, length(x$splits)))
})

tar_test("junction_upstream_edges()", {
names <- paste0("child_", seq_len(3))
x <- paste0("x_", seq_len(3))
Expand Down

0 comments on commit ac7344c

Please sign in to comment.