diff --git a/R/class_branch.R b/R/class_branch.R index f0f15d66..d5f8b5ee 100644 --- a/R/class_branch.R +++ b/R/class_branch.R @@ -8,7 +8,10 @@ branch_init <- function( store = NULL, index = NULL ) { - deps <- setdiff(unique(c(deps_parent, deps_child)), settings$dimensions) + deps <- setdiff_chr( + x = unique.default(c(deps_parent, deps_child)), + y = settings$dimensions + ) branch_new( name = name, command = command, diff --git a/R/utils_data.R b/R/utils_data.R index 2993d6bc..a06ec5b2 100644 --- a/R/utils_data.R +++ b/R/utils_data.R @@ -46,6 +46,10 @@ set_names <- function(x, names) { x } +setdiff_chr <- function(x, y) { + x[!duplicated.default(x) & (match(x, y, 0L) == 0L)] +} + sort_chr <- function(x) { old_locale <- Sys.getlocale(category = "LC_COLLATE") on.exit(Sys.setlocale(category = "LC_COLLATE", locale = old_locale)) diff --git a/tests/testthat/test-utils_data.R b/tests/testthat/test-utils_data.R index 554a5cce..14463a63 100644 --- a/tests/testthat/test-utils_data.R +++ b/tests/testthat/test-utils_data.R @@ -55,6 +55,12 @@ tar_test("supported_args()", { ) }) +tar_test("setdiff_chr()", { + expect_equal(setdiff_chr("x", character(0L)), "x") + expect_equal(setdiff_chr(character(0L), "x"), character(0L)) + expect_equal(setdiff(c("d", "a", "b"), "a"), c("d", "b")) +}) + tar_test("sort_chr()", { expect_equal(sort_chr(c("a", "b")), c("a", "b")) expect_equal(sort_chr(character(0L)), character(0L))