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 class of inputs to functions #50

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Check class of inputs to functions #50

merged 4 commits into from
Mar 12, 2024

Conversation

matt-dray
Copy link
Collaborator

@matt-dray matt-dray commented Mar 11, 2024

This is a starting point for input error-checking that gets us closer to closing #28 (which suggests more error-checks than class alone).

This PR adds an error-helper function that checks the class of inputs and provides tests (including snapshot tests for the rich error messages). Note that this adds dependencies on {rlang} and {cli}.

For now we only need to check numeric inputs, but I've added an expected_class argument that can check for character inputs as well. We can expand this later if we also need to check for data.frames, lists, etc.

This PR replaces #45 (closed draft), which had a less-good version of the class-checking function. It also had a function to check that the length of inputs match, but recycling is default R behaviour and it might surprise users if we raise an error (though we might be able to intercept the warning that's thrown with something a bit more friendly). We should discuss this further.

I've removed the skeleton tests written by Chris, which will calm the linter down. These skeletons are in version history, so we can always go back and copy them if required in future.

@matt-dray matt-dray self-assigned this Mar 11, 2024
Copy link
Collaborator

@ThomUK ThomUK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Matt!

@matt-dray matt-dray merged commit ac76b05 into main Mar 12, 2024
9 of 10 checks passed
@matt-dray matt-dray deleted the 28-check-input-class branch March 12, 2024 15:26
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

Successfully merging this pull request may close these issues.

None yet

2 participants