From 0848d34559c1307ab1245e5a4efdddb7b25600ac Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Thu, 8 Feb 2024 18:16:33 -0800 Subject: [PATCH] Update standalone-checks.R --- R/standalone-checks.R | 49 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/R/standalone-checks.R b/R/standalone-checks.R index 58240af..a4ccc5c 100644 --- a/R/standalone-checks.R +++ b/R/standalone-checks.R @@ -50,16 +50,53 @@ check_class <- function(x, class, allow_empty = FALSE, #' @inheritParams check_class #' @keywords internal #' @noRd -check_class_data_frame <- function(x, allow_empty = FALSE, - message = "The {.arg {arg_name}} argument must be class +check_data_frame <- function(x, allow_empty = FALSE, + message = "The {.arg {arg_name}} argument must be class {.cls {class}}, not {.obj_type_friendly {x}}.", - arg_name = rlang::caller_arg(x), call = parent.frame()) { + arg_name = rlang::caller_arg(x), call = parent.frame()) { check_class( x = x, class = "data.frame", allow_empty = allow_empty, message = message, arg_name = arg_name, call = call ) } +#' Check Class Logical +#' +#' @inheritParams check_class +#' @keywords internal +#' @noRd +check_logical <- function(x, allow_empty = FALSE, + message = "The {.arg {arg_name}} argument must be class + {.cls {class}}, not {.obj_type_friendly {x}}.", + arg_name = rlang::caller_arg(x), call = parent.frame()) { + check_class( + x = x, class = "logical", allow_empty = allow_empty, + message = message, arg_name = arg_name, call = call + ) +} + +#' Check Class Logical and Scalar +#' +#' @inheritParams check_class +#' @keywords internal +#' @noRd +check_scalar_logical <- function(x, allow_empty = FALSE, + message = "The {.arg {arg_name}} argument must be a scalar with class + {.cls {class}}, not {.obj_type_friendly {x}}.", + arg_name = rlang::caller_arg(x), call = parent.frame()) { + check_logical( + x = x, allow_empty = allow_empty, + message = message, arg_name = arg_name, + call = call + ) + + check_scalar( + x = x, allow_empty = allow_empty, + message = message, arg_name = arg_name, + call = call + ) +} + #' Check Argument not Missing #' #' @inheritParams check_class @@ -144,11 +181,11 @@ check_range <- function(x, include_bounds = c(FALSE, FALSE), message = paste0( - "The {.arg {arg_name}} argument must be in the interval + "The {.arg {arg_name}} argument must be in the interval {.code {ifelse(include_bounds[1], '[', '(')}{range[1]}, {range[2]}{ifelse(include_bounds[2], ']', ')')}}", - ifelse(scalar, " and length {.val {1}}", ""), - "."), + ifelse(scalar, " and length {.val {1}}", ""), + "."), scalar = FALSE, allow_empty = FALSE, arg_name = rlang::caller_arg(x),