The goal of exceptional is to create better exception handling. This is achived by:
warning()
or stop()
can deliver. Again, this is possible through the class "exceptional".This is a basic example:
library("exceptional")
Instead of
message("I am pretty urgent")
#> I am pretty urgent
We could do
my_alert <- create_exception(
create_message(default = "I am pretty urgent"),
nature = "warning",
cause = "because the weather is getting bad. Look at the clouds",
parameter = letters[1:3],
id = create_id("mypackage", 1)
)
my_alert
#> [WARNING] I am pretty urgent
my_alert$parameter
#> [1] "a" "b" "c"
Exceptions should have a unique id composed of the package name and a number and may be documented.
my_alert$id
#> [1] "mypackage-1"
my_alert$cause
#> [1] "because the weather is getting bad. Look at the clouds"
We can also create different messages depending on the language setting.
f <- function() {
msg <- create_message(default = "That's in english", de = "Deutsche Nachricht")
create_exception(msg, nature = "error")
}
Sys.setenv(LANG = "en")
f()
#> [ERROR] That's in english
Sys.setenv(LANG = "de")
f()
#> [ERROR] Deutsche Nachricht
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.