R/chk-factor.R

Defines functions vld_factor chk_factor

Documented in chk_factor vld_factor

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

#' @describeIn chk_factor Validate Factor
#'
#' @examples
#' # vld_factor
#' vld_factor(factor("1"))
#' vld_factor(factor(0))
#' vld_factor("1")
#' vld_factor(1L)
#' @export
vld_factor <- function(x) is.factor(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.