diff --git a/R/class_lookup.R b/R/class_lookup.R index f4da74fa..1fc3c186 100644 --- a/R/class_lookup.R +++ b/R/class_lookup.R @@ -30,6 +30,10 @@ lookup_unset <- function(lookup, names) { } } +lookup_remove <- function(lookup, names) { + remove(list = names, envir = lookup) +} + lookup_validate <- function(lookup) { tar_assert_envir(lookup) } diff --git a/tests/testthat/test-class_lookup.R b/tests/testthat/test-class_lookup.R index bf351e69..ddaa60e1 100644 --- a/tests/testthat/test-class_lookup.R +++ b/tests/testthat/test-class_lookup.R @@ -24,6 +24,14 @@ tar_test("class lookup", { expect_silent(lookup_validate(lookup)) }) +tar_test("class lookup remove method", { + lookup <- lookup_new() + lookup_set(lookup, names = letters, value = TRUE) + expect_equal(sort(lookup_list(lookup)), sort(letters)) + lookup_remove(lookup, letters) + expect_equal(lookup_list(lookup), character(0L)) +}) + tar_test("class lookup methods on NULL objects", { expect_false(lookup_exists(NULL, "a")) expect_true(lookup_missing(NULL, "a"))