rlang
rlang copied to clipboard
Should dynamic dots support checking whether all elements are named?
rlang offers a family of functions that operate on list expressions (this includes enxprs, enquos, but also dots_list). Most of these functions offer optional support for enforcing list element names (with .named = TRUE) and some of them can check whether the names are unique (with . homonyms = "error").
One functionality that is notably missing is checking that all elements are named. Right now one has to do something like this:
set_variables <- function(...) {
vars <- enxprs(..., . homonyms = "error")
if(!is_named(vars)) abort("all variables must be named")
# ...
}
It would be nice if one instead could write something like
enxprs(..., . .named = "error", homonyms = "error")
and have an informative rlang-style error for problematic elements.
If the maintainers are interested in this kind of functionality, I could provide an initial implementation.
Edit: in the same spirit, it would be useful if the functions could check that no elements are named. So maybe .named = "none" would mean "throw an error if at least one element is named" and .named = "all" would mean "throw an error if not all elements are named" etc.
I'd also find this feature really helpful 🤞
I could imagine named = c("any", "all", "none", "impute") where the current default behavior is maintained and the named = TRUE is covered by named = "impute". That's a breaking change though...