r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
502 stars 140 forks source link

Check helper for "list of" things #1663

Open hadley opened 11 months ago

hadley commented 11 months ago

Something that could replace code like this:

if (!is_bare_list(dots)) {
  stop_input_type(dots, "a list")
}

if (!is_named(dots)) {
  cli::cli_abort(
    "All components of {.arg ...} must be named.",
    call = error_call
  )
}

type_ok <- map_lgl(dots, function(x) is_atomic(x) || is.null(x))
if (any(!type_ok)) {
  cli::cli_abort(
    "All elements of {.code ...} must be either an atomic vector or NULL."
  )
}