Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check_named() to standalone file. #1669

Open
mgirlich opened this issue Nov 10, 2023 · 1 comment
Open

Add check_named() to standalone file. #1669

mgirlich opened this issue Nov 10, 2023 · 1 comment

Comments

@mgirlich
Copy link
Contributor

mgirlich commented Nov 10, 2023

I frequently see checks that something is named, especially when using ..., e.g. in httr2::req_template():

req_template <- function(...) {
  if (length(dots) > 0 && !is_named(dots)) {
    cli::cli_abort("All elements of {.arg ...} must be named.")
  }
}

It might make sense to also check that the names are unique. So, this would basically become a version of vctrs::vec_names2(..., repair = "check_unique").

I also added an issue in r-lib/vctrs#1895 as I think it makes sense in both places.
Also see #1236 for a feature request for checking that dynamic dots are named.

It might also be worth to add check_unnamed() (though this is needed way less often).

Some places I found this check * `httr2::req_template()` * `httr2::modify_list()` * `tidyr::pack()` * `tidyr::separate_wider_regex()` * `tidyr::check_unique_names()` * `tidyr::separate_wider_delim()` (unnamed)
@JosiahParry
Copy link

I would quite like this too. I have a pretty janky function that I often use check_dots_named() for this very purpose:

function(dots, call = rlang::caller_env()) {
  if (!rlang::is_named2(dots)) {
    cli::cli_abort(
      "All arguments provided to {.arg ...} must be named",
      call = call
    )
  }
  invisible(dots)
}

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

No branches or pull requests

2 participants