rlang icon indicating copy to clipboard operation
rlang copied to clipboard

Should dynamic dots support checking whether all elements are named?

Open tzakharko opened this issue 4 years ago • 1 comments

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.

tzakharko avatar Jul 06 '21 14:07 tzakharko

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...

davidchall avatar Sep 16 '21 17:09 davidchall