From c5bd72100091b45add48ff810e2807b1b8f11f1f Mon Sep 17 00:00:00 2001 From: wlandau Date: Sun, 10 Nov 2024 07:49:52 -0500 Subject: [PATCH] add lookup_remove() --- R/class_lookup.R | 4 ++++ tests/testthat/test-class_lookup.R | 8 ++++++++ 2 files changed, 12 insertions(+) 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"))