parameters
parameters copied to clipboard
Use more informative check_arg
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.
Good call
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