r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
489 stars 131 forks source link

`is_dictionarish(NULL)` should return `TRUE` #1712

Open hadley opened 1 month ago

hadley commented 1 month ago

I think, because there are no names, hence the names are necessarily unique.

lionel- commented 1 month ago

On the other hand NULL is not a vector.

vctrs::vec_is(NULL)
#> [1] FALSE

is_vector(NULL)
#> [1] FALSE

On the other other hand, you can take the names and length of NULL:

names(NULL)
#> NULL

I'm just wondering what kind of invariants we can attribute to dictionaryish objects. Is it just that they have a length and names, and the names are unique?

This would be consistent with:

is_dictionaryish(env())
#> [1] TRUE

Do you remember what you needed this for? Having some examples of patterns that would be simplified by adding this special-case for NULL would be helpful to understand the relevant invariants.

hadley commented 1 month ago

I don't, but I suspect it was an argument where the default was NULL and the expected type was a list.