| safeExecute | R Documentation |
Executes an expression with comprehensive error handling. On error, logs the error and returns a default value instead of stopping execution. This is particularly useful in Shiny reactive contexts where errors should be handled gracefully.
safeExecute(
expr,
module = "unknown",
default = NULL,
silent = FALSE,
notify = FALSE
)
expr |
An expression to evaluate. |
module |
character. Name of the calling module for logging purposes. |
default |
The value to return if an error occurs. Defaults to NULL. |
silent |
logical. If TRUE, suppresses the error and warning logging. Defaults to FALSE. |
notify |
logical. If TRUE and in a Shiny context, shows a notification to the user. Defaults to FALSE. |
The result of evaluating expr, or default if an
error occurs.
logModuleEvent for logging
# Returns 4
safeExecute({ 2 + 2 }, module = "test")
# Returns NULL and logs error
safeExecute({ stop("Error!") }, module = "test")
# Returns custom default on error
safeExecute({ stop("Error!") }, module = "test", default = data.frame())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.