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

Use more informative check_arg #1031

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Use more informative check_arg #1031

wants to merge 9 commits into from

Conversation

strengejacke
Copy link
Member

No description provided.

R/utils.R Outdated Show resolved Hide resolved
Co-authored-by: Brenton M. Wiernik <bwiernik@users.noreply.github.com>
@strengejacke
Copy link
Member Author

Maybe, when we have this wording, it would make sense to remove the suggested options from those that follow after "Otherwise...". Else, they would be duplicated.

@bwiernik
Copy link
Contributor

Good call

@strengejacke
Copy link
Member Author

strengejacke commented Oct 19, 2024

I added that function to insight, so we can use it in other packages, too:

library(insight)
foo1 <- function(test = "short_distance") {
  validate_argument(test, c("short_distance", "long_distance", "medium_distance"))
}

# match
foo1("medium_distance")
#> [1] "medium_distance"

# typo
foo1("medium_ditsance")
#> Error: Invalid option for argument `test`. Did you mean "medium_distance"?
#>   Otherwise, use one of the following options: "short_distance" or
#>   "long_distance"

# no match
foo1("abcabcabc")
#> Error: Invalid option for argument `test`. Please use one of the following
#>   options: "short_distance", "long_distance" or "medium_distance"

Created on 2024-10-19 with reprex v2.1.1

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.

2 participants