You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently discovered assertthat and I'm loving it. However, I ran into a little snag.
I find the name of the function is.count somewhat confusing. In my usage, a "count" should include the possibility that the count of x is zero, yet is.count(x) returns FALSE if x is zero. Perhaps I'm not thinking broadly enough, but I cannot readily think of any use case where it is impossible for a count to be zero. If such cases exist, I would expect them to be the exception rather than the rule.
Rather than quibbling on what properly or intuitively constitutes a "count", I propose the creation of two new functions that use well-defined mathematical terms to unambiguously specify the difference:
# TRUE if x is a natural number (positive integer, zero excluded)
is.natural <- function(x) {
assertthat::is.count(x)
}
# TRUE if x is a whole number (non-negative integer, zero included)
is.whole <- function(x) {
assertthat::is.count(x) || x == 0
}
Since assertthat::is.count is probably extensively used in existing packages, this proposal would not affect existing code yet it would probably help new users of assertthat avoid all the bugs I ran into because of my different understanding of what constitutes a "count"!
If this proposal is approved, I could write the code, test it with testthat, and then create a pull request.
The text was updated successfully, but these errors were encountered:
I recently discovered
assertthat
and I'm loving it. However, I ran into a little snag.I find the name of the function
is.count
somewhat confusing. In my usage, a "count" should include the possibility that the count of x is zero, yetis.count(x)
returns FALSE if x is zero. Perhaps I'm not thinking broadly enough, but I cannot readily think of any use case where it is impossible for a count to be zero. If such cases exist, I would expect them to be the exception rather than the rule.Rather than quibbling on what properly or intuitively constitutes a "count", I propose the creation of two new functions that use well-defined mathematical terms to unambiguously specify the difference:
Since
assertthat::is.count
is probably extensively used in existing packages, this proposal would not affect existing code yet it would probably help new users ofassertthat
avoid all the bugs I ran into because of my different understanding of what constitutes a "count"!If this proposal is approved, I could write the code, test it with
testthat
, and then create a pull request.The text was updated successfully, but these errors were encountered: