Skip to content

Commit

Permalink
is_dictionaryish(NULL) now returns true (#1741)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovemane authored Aug 15, 2024
1 parent c8e06b9 commit d2829e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion R/attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
}
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})

0 comments on commit d2829e2

Please sign in to comment.