diff --git a/NEWS.md b/NEWS.md index d9e0aabae..af45d9517 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ * `env_unlock()` is now defunct because recent versions of R no long make it possible to unlock an environment (#1705). Make sure to use an up-to-date version of pkgload (>= 1.4.0) following this change. + +* `is_dictionaryish()` now will return TRUE for NULL (@ilovemane, #1712). # rlang 1.1.4 diff --git a/R/attr.R b/R/attr.R index 04e3bf10d..f3b42290e 100644 --- a/R/attr.R +++ b/R/attr.R @@ -20,7 +20,7 @@ #' a logical vector as long as the input. #' #' @details -#' `is_named()` always returns `TRUE` for empty vectors because +#' `is_named()` always returns `TRUE` for empty vectors because #' #' @examples #' # is_named() is a scalar predicate about the whole vector of names: @@ -110,6 +110,10 @@ detect_void_name <- function(x) { is_dictionaryish <- function(x) { # 2022-01: Used in many packages. Don't deprecate without a # replacement. + if (is.null(x)) { + return(TRUE) + } + if (!length(x)) { return(!is.null(x)) } @@ -118,6 +122,7 @@ is_dictionaryish <- function(x) { } + #' Does an object have an element with this name? #' #' This function returns a logical value that indicates if a data diff --git a/tests/testthat/test-attr.R b/tests/testthat/test-attr.R index 79e00b755..cd5496e31 100644 --- a/tests/testthat/test-attr.R +++ b/tests/testthat/test-attr.R @@ -186,3 +186,8 @@ test_that("zap_srcref() works on calls", { expect_null(attributes(zap_srcref(call))) expect_true("srcref" %in% names(attributes(call))) }) + +test_that("is_dictionaryish return true if is NULL", { + + expect_true(is_dictionaryish(NULL)) +})