loading...

stop_greater_or_equal() generates an error message for >= assertions.

stop_greater_or_equal(
  lhs,
  rhs,
  ...,
  mod = NULL,
  na.rm = FALSE,
  test_it = TRUE,
  par. = list()
)

`stop_>=`(
  lhs,
  rhs,
  ...,
  mod = NULL,
  na.rm = FALSE,
  test_it = TRUE,
  par. = list()
)

Arguments

lhs

The left-hand side of the comparison.

rhs

The right-hand side of the comparison.

...

Additional arguments (not used yet).

mod

A character string indicating the modifier to use for the comparison ("", "any", or "all"). Default is NULL, which is equivalent to "".

na.rm

Logical, indicating whether missing values should be removed before performing the comparison. Default is FALSE.

test_it

Logical, indicating whether the comparison should be actually tested. Default is TRUE. If FALSE, the function only constructs the error message based on the lengths of lhs and rhs, and the presence of missing values.

par.

A list of parameters to customize the error message. Optional fields include msg (message(s) to display at the top), footer(message(s) to add at the bottom), arg (name of first argument), arg2 (name of second argument), id (error class id), mod (the modifier, see mod above), call (the call where the error was generated).

Value

This function always stops with an error.

Examples

x <- 1
stop_greater_or_equal(x, 3) |> try()
#> Error in eval(expr, envir) : ! `x` must be >= `3`.
#>  `x` is: 1.
x <- 1:2
# Should not call stop_greater_or_equal() on the following one
stop_greater_or_equal(x, c(0, 3), mod = "any") |> try()
#> Error in eval(expr, envir) : 
#>   ! At least one is TRUE in `x` >= `c(0, 3)`.
#>  Should be OK, but `stop_greater_or_equal()` called anyway.
#>  This is an internal error, please report it to the package authors.
# but yes on the next one
stop_greater_or_equal(x, c(0, 3), mod = "all") |> try()
#> Error in eval(expr, envir) : 
#>   ! Not all `x` are >= `c(0, 3)`.
#>  Must all be >=.