R/chk-unused.R

Defines functions vld_unused chk_unused

Documented in chk_unused vld_unused

#' Check ... Unused
#'
#' @description
#' Checks if ... is unused
#'
#' `length(list(...)) == 0L`
#'
#' @inheritParams params
#' @inherit params return
#' @return The `chk_` function throws an informative error if the test fails.
#'
#' @family chk_ellipsis
#'
#' @examples
#' # chk_unused
#' fun <- function(x, ...) {
#'   chk_unused(...)
#'   x
#' }
#' fun(1)
#' try(fun(1, 2))
#' @export
chk_unused <- function(...) {
  if (!length(list(...))) {
    return(invisible())
  }
  abort_chk("`...` must be unused")
}

#' @describeIn chk_unused Validate ... Unused
#'
#' @examples
#' # vld_unused
#' fun <- function(x, ...) {
#'   vld_unused(...)
#' }
#' fun(1)
#' try(fun(1, 2))
#' @export
vld_unused <- function(...) length(list(...)) == 0L

Try the chk package in your browser

Any scripts or data that you put into this service are public.

chk documentation built on Oct. 6, 2023, 9:06 a.m.