Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dictionaryish(NULL) return true #1741

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this new unnecessary whitespace please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

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))
})
Loading