Skip to contents

Copyright(c) 2017-2025 R. Mark Sharp This file is part of nprcgenekeepr

Usage

safeExecute(
  expr,
  module = "unknown",
  default = NULL,
  silent = FALSE,
  notify = FALSE
)

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.

Value

The result of evaluating expr, or default if an error occurs.

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())
} # }