throw: Generate and Signal Condition

View source: R/throw.R

throwR Documentation

Generate and Signal Condition

Description

Generate and signal a condition.

Usage

throw(general, specifics = NULL, env = NULL, as = "error", class = NULL, ...)

Arguments

general

A single character which gives a general statement of the condition.

specifics

Optional. A character vector which gives a list of details of the condition. If is character(0), throw() will return silently. If is a named vector, the names are used to create bullets. If the name is "x" or "i", the bullet will be colored and bold. The default name is "x". You can customize bullets with option erify.bullets.

env

Optional. An environment or named list which is used to evaluate the R code in the above arguments. See glue::glue().

as

Optional. "error", "warning" or "message" which indicates how to signal the condition. The default value is "error".

class

Optional. A character vector which assigns classes to the condition.

...

Optional. Additional arguments which are stored in the condition and can be retrieved with tryCatch().

Value

If specifics is character(0), returns an invisible NULL. Or signals an error, a warning, or a message.

Examples

general <- "You are wrong."

# returns silently
throw(general, character(0))

## Not run: 
throw(general)

specifics <- c("Detail 1.", i = "Detail 2.")
throw(general, specifics)

# embed R code with glue syntax
throw("`x` is {x}.", env = list(x = 1))

## End(Not run)

# add and retrieve additional argument
tryCatch(
  { throw(general, arg = "I'm an additional argument.") },
  error = function(e) e$arg
)

erify documentation built on Oct. 4, 2022, 5:07 p.m.