tryWithWarnings: Run an Expression and Catch Warnings and Errors

View source: R/tryWithWarnings.R

tryWithWarningsR Documentation

Run an Expression and Catch Warnings and Errors

Description

Similar to try but also returns warnings.

Usage

tryWithWarnings(expr)

Arguments

expr

the line of code to be evaluated

Details

from https://stackoverflow.com/questions/4948361/how-do-i-save-warnings-and-errors-as-output-from-a-function

Value

A list containing:

  • value the result of the evaluation of the expression

  • warnings warning(s) generated during the evaluation of the expression

  • error error generated during the evaluation of the expression

Examples

FctTest <- function(x){
  return(log(x))
}
tryWithWarnings(FctTest(-1))
tryWithWarnings(FctTest(1))
tryWithWarnings(FctTest(xxxx))


lavaSearch2 documentation built on April 12, 2023, 12:33 p.m.