mllg / checkmate

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

Behaviour for empty vectors when `all.missing = TRUE` #203

Closed mb706 closed 3 years ago

mb706 commented 3 years ago
> checkNumeric(numeric(0), all.missing=FALSE)
[1] "Contains only missing values"

The documentation / error message for all.missing is maybe a bit ambiguous, since the empty vector does not contain any missing values. Maybe rephrase this to no non-missing values, and clarify the documentation that empty vectors are not accepted?

mmuurr commented 3 years ago

I struggle with this, too. There are times that I want to:

  1. allow for an empty vector (e.g. logical(0))
  2. but not NULL (i.e. null.ok = FALSE)
  3. and disallow any NA values from appearing in a non-empty vector -- i.e. where both any.missing = FALSE and all.missing = FALSE, since both c(TRUE, NA) and c(NA, NA) should fail.

So, for typed vectors, effectively something like empty.ok = TRUE.

mllg commented 3 years ago

I've improved the documentation as suggested by @mb706. AFAICT the use case of @mmuurr seems to be rather unusual, so I guess introducing a new argument for this is not justified. I believe you could solve this by simply doing 2 assertions?