Skip to content

Commit d2829e2

Browse files
authored
is_dictionaryish(NULL) now returns true (#1741)
1 parent c8e06b9 commit d2829e2

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* `env_unlock()` is now defunct because recent versions of R no long
77
make it possible to unlock an environment (#1705). Make sure to use an
88
up-to-date version of pkgload (>= 1.4.0) following this change.
9+
10+
* `is_dictionaryish()` now will return TRUE for NULL (@ilovemane, #1712).
911

1012

1113
# rlang 1.1.4

R/attr.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' a logical vector as long as the input.
2121
#'
2222
#' @details
23-
#' `is_named()` always returns `TRUE` for empty vectors because
23+
#' `is_named()` always returns `TRUE` for empty vectors because
2424
#'
2525
#' @examples
2626
#' # is_named() is a scalar predicate about the whole vector of names:
@@ -110,6 +110,10 @@ detect_void_name <- function(x) {
110110
is_dictionaryish <- function(x) {
111111
# 2022-01: Used in many packages. Don't deprecate without a
112112
# replacement.
113+
if (is.null(x)) {
114+
return(TRUE)
115+
}
116+
113117
if (!length(x)) {
114118
return(!is.null(x))
115119
}
@@ -118,6 +122,7 @@ is_dictionaryish <- function(x) {
118122
}
119123

120124

125+
121126
#' Does an object have an element with this name?
122127
#'
123128
#' This function returns a logical value that indicates if a data

tests/testthat/test-attr.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,8 @@ test_that("zap_srcref() works on calls", {
186186
expect_null(attributes(zap_srcref(call)))
187187
expect_true("srcref" %in% names(attributes(call)))
188188
})
189+
190+
test_that("is_dictionaryish return true if is NULL", {
191+
192+
expect_true(is_dictionaryish(NULL))
193+
})

0 commit comments

Comments
 (0)