| 1 |
check_string <- function(x, arg = caller_arg(x), call = caller_env()) { |
| 2 |
if (!is_string(x)) { |
| 3 |
cli::cli_abort("{.arg {arg}} must be a string", arg = arg, call = call) |
| 4 |
} |
| 5 |
} |
| 6 |
|
| 7 |
check_bool <- function(x, arg = caller_arg(x), call = caller_env()) { |
| 8 |
if (!is_bool(x)) { |
| 9 |
cli::cli_abort("{.arg {arg}} must be TRUE or FALSE", arg = arg, call = call) |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
check_count <- function(x, inf = FALSE, arg = caller_arg(x), call = caller_env()) { |
| 14 |
finite <- if (inf) NULL else TRUE |
| 15 |
if (!is_scalar_integerish(x, finite = finite) || is.na(x) || x <= 0) { |
| 16 |
cli::cli_abort("{.arg {arg}} must be a positive integer", arg = arg, call = call) |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
check_inherits <- function(x, cls, arg = caller_arg(x), call = caller_env()) { |
| 21 |
if (!inherits(x, cls)) { |
| 22 |
cli::cli_abort("{.arg {arg}} must be a {.cls {cls}} object", arg = arg, call = call) |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
check_file_exists <- function(x, arg = caller_arg(x), call = caller_env()) { |
| 27 |
if (!fs::file_exists(x) || fs::dir_exists(x)) { |
| 28 |
cli::cli_abort("File does not exist: {.file {x}}", arg = arg, call = call) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
check_dir_exists <- function(x, arg = caller_arg(x), call = caller_env()) { |
| 33 |
if (!fs::dir_exists(x)) { |
| 34 |
cli::cli_abort("Directory does not exist: {.path {x}}", arg = arg, call = call) |
| 35 |
} |
| 36 |
} |