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

check single integer #49

Closed
surmann opened this issue May 13, 2015 · 5 comments
Closed

check single integer #49

surmann opened this issue May 13, 2015 · 5 comments

Comments

@surmann
Copy link

surmann commented May 13, 2015

How do I check a single integer value? Currently I use assertInteger(x, any.missing=FALSE, len=1). Do I overlook a function, because I expected one with a shorter call similar to e.g. checkInt.

@berndbischl
Copy link
Collaborator

RTFM you bloody noob !!!!

Hi Dirk, more seriuosly there is this overview, that mentions scalars
https://github.com/mllg/checkmate

There is checkInt and checkCount?

@surmann
Copy link
Author

surmann commented May 14, 2015

Take it from me, I did!

I looked at checkInt, checkCount and all the others that check numeric values. However, in my opinion they seem to be for real or integerish values, not for native integer values because of the tol value. checkInt(4) is TRUE but not checkInteger(4).

Probably I interpret or use some functions in a wrong manner?

@berndbischl
Copy link
Collaborator

So, you want to function that lets 1L pass, but not 1?

@berndbischl
Copy link
Collaborator

What I should add here:
Nearly always I want this behavior: I have a function f(k) where k is supposed to be an int.
Now, a user should be able to say f(1L) and f(1), as
a) most users do not even really know that 1 is NOT an int. I dont want to hassle them with an error.
b) typing the L might be cumbersome

So what i do is
k = asInt(k)

  • That performs a check whether k is "integerish", so allow 1 as well
  • after the above line I have type-safety, so I know that k is now really of type "integer" in my code, as it is potentially converted from 1 to 1L

Does that make sense?

@surmann
Copy link
Author

surmann commented May 15, 2015

First Comment: Yes.
Second Comment: That makes sense, I will use it this way.

Thanks!

@surmann surmann closed this as completed May 15, 2015
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

2 participants