parameters icon indicating copy to clipboard operation
parameters copied to clipboard

Use more informative check_arg

Open strengejacke opened this issue 1 year ago • 3 comments

strengejacke avatar Oct 18 '24 14:10 strengejacke

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.

strengejacke avatar Oct 18 '24 20:10 strengejacke

Good call

bwiernik avatar Oct 18 '24 21:10 bwiernik

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

strengejacke avatar Oct 19 '24 08:10 strengejacke