Copyright(c) 2017-2025 R. Mark Sharp This file is part of nprcgenekeepr
Arguments
- 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 notification. Defaults to FALSE.
- notify
logical. If TRUE and in a Shiny context, shows a notification to the user. Defaults to FALSE.
Details
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.
See also
logModuleEvent for logging
Examples
if (FALSE) { # \dontrun{
# 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())
} # }
