Learn R Programming

tryCatchLog (version 1.0.2)

tryLog: Try an expression with condition logging and error recovery

Description

tryLog is a wrapper function around tryCatchLog that traps any errors that occur during the evaluation of an expression without stopping the execution of the script (similar to try). Errors, warnings and messages are logged. In contrast to tryCatchLog it returns but does not stop in case of an error and therefore does not have the error and finally parameters to pass in custom handler functions.

Usage

tryLog(expr,
  write.error.dump.file = getOption("tryCatchLog.write.error.dump.file",
  FALSE), silent.warnings = getOption("tryCatchLog.silent.warnings", FALSE),
  silent.messages = getOption("tryCatchLog.silent.messages", FALSE))

Arguments

expr

expression to be evaluated

write.error.dump.file

TRUE: Saves a dump of the workspace and the call stack named dump_<YYYYMMDD_HHMMSS>.rda

silent.warnings

TRUE: Warnings are logged, but not propagated to the caller. FALSE: Warnings are logged and treated according to the global setting in getOption("warn"). See also warning.

silent.messages

TRUE: Messages are logged, but not propagated to the caller. FALSE: Messages are logged and propagated to the caller.

Value

The value of the expression (if expr is evaluated without an error. In case of an error: An invisible object of the class "try-error" containing the error message and error condition as the "condition" attribute.

Details

tryLog is implemented using tryCatchLog. If you need need more flexibility for catching and handling errors use the latter. Error messages are never printed to the stderr connection but logged only.

See Also

tryCatchLog, last.tryCatchLog.result

Examples

Run this code
# NOT RUN {
tryLog(log(-1))   # logs a warning
tryLog(log("a"))  # logs an error
# }

Run the code above in your browser using DataLab