throw: Generate and Signal Condition

Description Usage Arguments Value Examples

View source: R/throw.R

Description

Generate and signal a condition.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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 May 30, 2021, 5:06 p.m.