Skip to contents

The function allows to run same function (e.g. check_length()) on more than one argument. It will throw error on first argument that fails internal test.

Usage

check_multiple(.args, .f, ...)

Arguments

.args

Arguments that will be tested with same inside test, called with [check_args()] function.

.f

Test function name.

...

Additional arguments to function call.

Value

Error if any of the argument fails.

Examples

if (FALSE) { # \dontrun{
  int_1 <- c(55L)
  num_1 <- c(5.5)
  nl1 <- NULL
  int_1_n <- c(-66L)
  int_v <- c(1L, 3L, 666L)
  num_vec <- c(1.5, 3.14, 55)
  char_1 <- "check"
  char_v <- c("check", "if", "arg", "1")
  wrong_color <- c("dick")
  wrong_hex <- "#hex"
  check_multiple(
    check_args(int_1, int_v), check_class, arg_class = "integer"
  )
  check_multiple(
    check_args(int_1, int_v, char_v),
    check_class, arg_class = "integer",
    add_msg = "{.arg {x_name}} should be {.cls {arg_class}}."
  )
  check_multiple(check_args(char_1, char_v), check_length, arg_length = 1)
  check_multiple(
    check_args(char_1, char_v), check_scalar, arg_class = "character"
  )
  check_multiple(
    check_args(int_1, int_1_n), check_scalar_sign, arg_sign = "positive"
  )
  check_multiple(
    check_args(int_1, int_1_n), check_scalar_sign, arg_sign = "negative"
  )
  check_multiple(
    check_args(int_1, nl1), check_scalar, arg_class = "integer",
    alt_null = TRUE
  )
  check_multiple(check_args(wrong_color, wrong_hex), check_color)
} # }