Skip to content

Conversation

@strengejacke
Copy link
Member

No description provided.

Co-authored-by: Brenton M. Wiernik <[email protected]>
@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

@strengejacke strengejacke merged commit a37c5e4 into main Oct 24, 2024
19 of 20 checks passed
@strengejacke strengejacke deleted the use_check_arg branch October 24, 2024 13:17
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.

3 participants