-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add function input checks #28
Comments
Great idea Matt. are you putting this together? I'm going to start adding some tests as part of #7 . |
Adding my Slack comment here for visibility and discussion. Perhaps this should start with simple |
I think we probably have to handle integers, as it should probably be possible for people to supply decimal inputs (e.g. 25.5 week target). It's probably not common, but it shouldn't bug out. I like the idea of Also need a descriptive message for when inputs are missing. |
Bingo, should be nice and versatile. It can be messy to make a lot of Phrasing is currently along the lines of:
This phrasing can be changed, of course. I was thinking about the Tidyverse style guide section on error messages. And yes, good point on missingness, thank you. |
Incidentally, I don't actually know what the best practice is for input checks like this. This is just how I've done it in the past! Advice very welcome. |
I think we are in the same boat here. I've written checks in the past, but they've been very bespoke and individual, so using a generic function is a step up for me. I've not heard anyone speak about that before either, I've just gleaned it from my own packages breaking with bad inputs and confusing users. For brevity, we could always call using something like |
…mented out in anticipation of input checks.
Someone sent me this article today, which has elegant ways of making sure the error messages reference the functions that the user is using, rather than the content and arguments of the checking functions. It's beyond anything I've implemented before, but I've made a mental note to consider it for my most-used packages. I usually stop with check functions and assumed that the slightly confusing error messgaes were a necessary consequence of cleaner reading code. https://www.njtierney.com/post/2023/12/06/long-errors-smell/ |
Oh wow, Nick Tierney is clearly on our wavelength. As it happens, I was coding something earlier that looks basically like what he's come up with there. Except the check functions I've written take multiple inputs via |
Note to self/us: there was also an R-Hub post on {cli} tips and tricks recently. |
Accept only 'correct' argument inputs for each function. Provide useful error messaging to users on failure.
This will impact the range of tests that can be developed as part of #7.
It's probably best to put these checks in a
utils.R
file, given that similar checks can be used across functions.This applies to the core functions that exist at time of writing. More checks will be required as the package's functionality expands.
Perhaps start with base
stop()
to begin with. Could make later use of the {cli} package for a slicker interface.The text was updated successfully, but these errors were encountered: