R/deprecated.R

Defines functions deparse_backtick chk_proportion is_chk_on chk_on chk_off vld_no_missing chk_no_missing chk_in chk_has chk_files chk_dirs

Documented in chk_dirs chk_files chk_has chk_in chk_no_missing chk_off chk_on chk_proportion deparse_backtick is_chk_on vld_no_missing

#' Deprecated functions
#'
#'
#' Deprecated `chk_()` functions.
#'
#' @family deprecated
#'
#' @inheritParams chk_flag
#' @return The `chk_` functions throw an informative error if the test fails and
#' otherwise return invisibly.
#' `vld_no_missing()` returns a flag indicating whether `x` has no missing
#' values and `deparse_backtick()` returns a string.
#' `chk_off()`, `chk_on()` and `is_chk_on()` are defunct and always throw an
#' error.
#' @keywords internal
#' @name chk_deprecated
#' @examples
#' # The deprecated functions signal a deprecation warning when called.
#' chk_has(1:2, 1)
#' chk_in(1, 1:2)
#' chk_no_missing(1)
#' vld_no_missing(1)
#' chk_proportion(0.5)
#' deparse_backtick(quote(x))
#'
#' # The defunct functions always throw an error.
#' try(chk_on())
NULL

#' @describeIn chk_deprecated Check Directories Exist
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace with `[chk_all](x, [chk_dir])`
#'
#' @export
chk_dirs <- function(x) {
  deprecate_warn(
    "0.2.0",
    what = "chk::chk_dirs()",
    details = "Please use `chk_all(x, chk_dir)` instead"
  )
  chk_all(x, chk_dir)
}

#' @describeIn chk_deprecated Check Files Exist
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace with `[chk_all](x, [chk_file])`
#'
#' @export
chk_files <- function(x) {
  deprecate_warn(
    "0.2.0",
    what = "chk::chk_files()",
    details = "Please use `chk_all(x, chk_file)` instead"
  )
  chk_all(x, chk_file)
}

#' @describeIn chk_deprecated Check Has
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace by [chk_superset()]
#'
#' @export
chk_has <- function(x, values, x_name = NULL) {
  if (is.null(x_name)) {
    x_name <- deparse_backtick_chk(substitute(x))
  }
  chk_superset(x, values, x_name = x_name)
  deprecate_warn("0.2.0", what = "chk::chk_has()", with = "chk::chk_superset()")
  invisible()
}

#' @describeIn chk_deprecated Check In
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace by [chk_subset()]
#'
#' @export
chk_in <- function(x, values, x_name = NULL) {
  if (is.null(x_name)) {
    x_name <- deparse_backtick_chk(substitute(x))
  }
  chk_subset(x, values, x_name = x_name)
  deprecate_warn("0.2.0", what = "chk::chk_in()", with = "chk::chk_subset()")
  invisible()
}

#' @describeIn chk_deprecated Check No Missing Values
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace with [chk_not_any_na()]
#'
#' @export
chk_no_missing <- function(x, x_name = NULL) {
  deprecate_warn(
    "0.2.0",
    what = "chk::chk_no_missing()",
    with = "chk::chk_not_any_na()",
    id = "chk_no_missing"
  )
  if (vld_no_missing(x)) {
    return(invisible())
  }
  if (is.null(x_name)) {
    x_name <- deparse_backtick_chk(substitute(x))
  }
  abort_chk(x_name, " must not have missing values", x = x)
}

#' @describeIn chk_deprecated Validate No Missing Values
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace with [vld_not_any_na()]
#'
#' @export
vld_no_missing <- function(x) {
  deprecate_warn(
    "0.2.0",
    what = "chk::vld_no_missing()",
    with = "chk::vld_not_any_na()",
    id = "chk_no_missing"
  )
  !anyNA(x)
}

#' @describeIn chk_deprecated Turns checking off
#'
#' `r lifecycle::badge("deprecated")`
#'
#' This approach is no longer recommended
#'
#' @export
chk_off <- function() {
  deprecate_stop(
    "0.2.0",
    what = "chk::chk_off()",
    details = "This approach is no longer recommended"
  )
  options(chk.on = FALSE)
}

#' @describeIn chk_deprecated Turns checking on
#'
#' `r lifecycle::badge("deprecated")`
#'
#' This approach is no longer recommended
#'
#' @export
chk_on <- function() {
  deprecate_stop(
    "0.2.0",
    what = "chk::chk_on()",
    details = "This approach is no longer recommended"
  )
  options(chk.on = TRUE)
}

#' @describeIn chk_deprecated Tests checking on
#'
#' `r lifecycle::badge("deprecated")`
#'
#' This approach is no longer recommended
#'
#' @export
is_chk_on <- function() {
  deprecate_stop(
    "0.2.0",
    what = "chk::is_chk_on()",
    details = "This approach is no longer recommended"
  )
  getOption("chk.on", TRUE)
}

#' @describeIn chk_deprecated Check Proportion
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace by `[chk_number](x); [chk_range](x)`
#'
#' @export
chk_proportion <- function(x, x_name = NULL) {
  deprecate_warn(
    "0.2.0",
    what = "chk::chk_proportion()",
    details = "Please use `chk_number(x)` or `chk_range(x)` instead"
  )
  if (is.null(x_name)) {
    x_name <- deparse_backtick_chk(substitute(x))
  }
  chk_number(x)
  chk_range(x)
}

#' @describeIn chk_deprecated Deparse Backtick
#'
#' `r lifecycle::badge("deprecated")`
#'
#' Replace with [deparse_backtick_chk()]
#'
#' @export
deparse_backtick <- function(x) {
  deprecate_warn(
    "0.2.0",
    what = "chk::deparse_backtick()",
    with = "chk::deparse_backtick_chk()"
  )
  deparse_backtick_chk(x)
}

Try the chk package in your browser

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

chk documentation built on Sept. 3, 2026, 9:07 a.m.