stopifnot: Conditional Stop Log Handler

View source: R/handlers.R

stopifnotR Documentation

Conditional Stop Log Handler

Description

This function is identical to base R's stopifnot, but it includes logging of the exception message via loggit().

Usage

stopifnot(..., exprs, exprObject, local, .loggit = NA, echo = get_echo())

Arguments

..., exprs

any number of R expressions, which should each evaluate to (a logical vector of all) TRUE. Use either ... or exprs, the latter typically an unevaluated expression of the form

{
  expr1
  expr2
  ....
}

Note that e.g., positive numbers are not TRUE, even when they are coerced to TRUE, e.g., inside ⁠if(.)⁠ or in arithmetic computations in R. If names are provided to ..., they will be used in lieu of the default error message.

exprObject

alternative to exprs or ...: an ‘expression-like’ object, typically an expression, but also a call, a name, or atomic constant such as TRUE.

local

(only when exprs is used:) indicates the environment in which the expressions should be evaluated; by default the one from where stopifnot() has been called.

.loggit

Should the condition message be added to the log? If NA the log level set by set_log_level() is used to determine if the condition should be logged.

echo

Should the log entry (json) be echoed to stdout as well?

See Also

Other handlers: debuginfo(), message(), stop(), warning()

Examples

## Not run: 
 stopifnot("This is a completely false condition" = FALSE)

 stopifnot(5L == 5L, "This is a completely false condition" = FALSE, echo = FALSE)

## End(Not run)


loggit2 documentation built on June 8, 2025, 10:26 a.m.