mllg / checkmate

Fast and versatile argument checks
https://mllg.github.io/checkmate/
Other
265 stars 30 forks source link

`assert_date` NA missing behavior inconsistent with `assert_numeric` and others #256

Open dshemetov opened 10 months ago

dshemetov commented 10 months ago

Hello, first off thank you for this excellent package.

Secondly, this behavior seems inconsistent to me:

library(checkmate)

# Pass
assert_numeric(c(5, NA))
assert_date(c(Sys.Date(), NA))
# Pass
assert_numeric(NA)
assert_character(NA)
assert_integerish(NA)
assert_double(NA)
# Doesn't pass
assert_date(NA)
# Error: Assertion on 'NA' failed: Must be of class 'Date', not 'logical'.

This happens even though they all have the same defaults for any.missing = TRUE. Thoughts? Thanks for your time.

tdeenes commented 10 months ago

In your second example, c(Sys.Date(), NA) creates a Date vector, this is why it passes. @mllg Maybe check_date should get a typed.missing argument, too? Also related to https://github.com/mllg/checkmate/issues/236