R doesn’t come with a built-in constructor function for conditions, but we can easily add one.
(Advanced R, by Hadley Wickham)
Actually, there is simpleCondition(), simpleError() and the like,
but they don't allow specifying an additional class.
The functions in this package allow it:
library(condition) cond <- new_error("Something went wrong", class = "oops") cond is.error(cond)
Everything is powered by an R6 generator class that creates condition class objects:
Condition Error
These condition objects can be used instead the plain functions:
Error$new("Plain error")
If a custom condition is used more than once, it is a good idea to formalize it:
Oops <- ConditionClass$new("oops", Error) oops <- Oops$new("Something went wrong") oops Oops$is(oops)
A custom condition object inherits from its base:
Error$is(oops)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.