R/utils-errors.R

Defines functions stop_not_nested warn_ambiguous_column stop_bad_type stop_bad_class

stop_bad_class <- function(name, expected, actual, call = rlang::caller_env()) {
  cli::cli_abort(c(
    "{.arg {name}} must have class: {.cls {expected}}.",
    "i" = "Actual class: {.cls {actual}}."
  ), call = call, class = "bad_class")
}

stop_bad_type <- function(name, expected, actual, call = rlang::caller_env()) {
  cli::cli_abort(c(
    "{.arg {name}} must be {expected}, not {.obj_type_friendly {actual}}."
  ), call = call, class = "bad_type")
}

warn_ambiguous_column <- function(name, colname) {
  cli::cli_warn(c(
    "Ambiguous column to unnest in {.arg {name}}.",
    "Using column {.val {name}}."
  ))
}

stop_not_nested <- function(name, call = rlang::caller_env()) {
  cli::cli_abort(c(
    "{.arg {name}} is not nested.",
    "i" = "Try manually nesting the data with {.fun tidyr::nest}."
  ), call = call, class = "not_nested")
}

Try the nestedmodels package in your browser

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

nestedmodels documentation built on Sept. 30, 2023, 5:06 p.m.