tidymodels / model-implementation-principles

recommendations for creating R modeling packages
https://tidymodels.github.io/model-implementation-principles/
41 stars 4 forks source link

Don't use `match.arg()` to validate `type` #14

Open DavisVaughan opened 5 years ago

DavisVaughan commented 5 years ago

I disagree with the use of match.arg() for validation, as it accepts partial matches.

match.arg("res", c("response"))
#> [1] "response"

It is mentioned here: https://tidymodels.github.io/model-implementation-principles/model-predictions.html

I think type should default to whatever prediction type you think is going to be the most common, and then in the documentation you mention the other accepted values for the type.

Then match with rlang::arg_match() which does not accept partial matches and gives nice error messages.

type <- "resp"
choices <- c("response", "conf_int")
rlang::arg_match(type, choices)
#> Error: `type` should be one of: "response" or "conf_int"
#> Did you mean "response"?