R/chk-list.R

Defines functions vld_list chk_list

Documented in chk_list vld_list

#'  Check List
#'
#' @description
#' Checks if is a list using
#'
#' `is.list(x)`
#'
#' @inheritParams params
#' @inherit params return
#'
#' @family chk_typeof
#'
#' @examples
#' # chk_list
#' chk_list(list())
#' try(chk_list(1))
#' @export
chk_list <- function(x, x_name = NULL) {
  if (vld_list(x)) {
    return(invisible(x))
  }
  if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))
  abort_chk(x_name, " must be a list", x = x)
}

#' @describeIn chk_list Validate List
#'
#' @examples
#' # vld_list
#' vld_list(list())
#' vld_list(list(x = 1))
#' vld_list(mtcars)
#' vld_list(1)
#' vld_list(NULL)
#' @export
vld_list <- function(x) is.list(x)

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.