Closed bart1 closed 1 year ago
rlang predicates are about storage type. So you probably want to combine is_integerish()
with is.numeric()
.
Dear @lionel- thank you for the comment, I do recognize that and do understand the logic. Therefore I thought it would be good to document it (like is_integerish(TRUE)
in the example). As is_integerish
is not only about the storage mode (e.g. 10.0
as a double giving resulting in true), I suspect people want to use it mainly to avoid the result of is.integer(10)
resulting in FALSE
. (a quick random example i found: https://github.com/cran/hipread/blob/7c39e75486e06775040048988bca770af7c9341d/R/col_specs.R#L44 , I suspect the intention here is not to allow column selection with dates but rather to be more flexible how the numbers are written (disclaimer I don't know this package))
Would is.numeric
be preferred over is_bare_integerish
, if so why?
is_bare_integerish()
will return FALSE
for factors and dates, so you don't need to check for is.numeric()
with this predicate.
However you can use is.numeric(x) && is_integerish(x)
to check for integerish numeric vectors.
I agree it'd be nice to have a user-facing predicate that deals with all this, but it's still unclear at the moment if this should live in rlang or in vctrs.
There's some work on this front in standalone-check-types.R
. Still missing predicate and vector variants, but there's now check_number_whole()
and check_number_decimal()
.
Closing this in the meantime. Development will continue piecemeal.
I just noticed dates and times are considered integerish:
This makes some sense thinking about how these are stored, as they are integer like numbers internally. On the other hand boolean values fail on
is_integerish
even though they can also be presented as 0 or 1. So I'm not sure what is correct/desired. However, in the first instance, in code I was writing I expectedis_integerish
to fail on times and dates (is it maybeis_bare_integerish
i was looking for?). I think it would be good to atleast document this behavior in?is_integerish
so users are aware of this.