poissonconsulting / chk

An R package for developers to check user-supplied function arguments
https://poissonconsulting.github.io/chk/
Other
48 stars 4 forks source link

Add check for missing argument #113

Closed ngreifer closed 2 years ago

ngreifer commented 2 years ago

It would be great if there could be a chk_ and vld_ for a missing argument, i.e., when a function's formal argument has no default and the user doesn't supply anything to it, something like is.missing() but with the chk sugar around it. It might also be cool to have a check for whether the supplied argument is missing in all checking functions. Thanks!

joethorley commented 2 years ago

Thanks @ngreifer - we'll think about this

joethorley commented 2 years ago

I've implemented - the only limitation is that if the argument has a default it considers the argument to not be missing. I don't think this can be avoided because by definition chk_missing() is nested within the parent function and as the help file for missing states

Currently missing can only be used in the immediate body of the function that defines the argument, not in the body of a nested function or a local call. This may change in the future.

ngreifer commented 2 years ago

This looks great, thank you! If the argument has a default, it should not be considered missing, so this is correct behavior in my opinion.

That second part is a limitation, but not one I know how to deal with. It is possible to create a missing value to compare something to, but as soon as it is passed to nested functions it attempts to evaluate the argument. Still, for basic argument checking, it is helpful.

github-actions[bot] commented 4 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.