Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: is.natural and is.whole functions to disambiguate is.count #80

Open
tripartio opened this issue Sep 14, 2023 · 0 comments
Open

Comments

@tripartio
Copy link

tripartio commented Sep 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant