ifnerror: If-else Wrapper for Errors

Description Usage Arguments Details See Also Examples

Description

Tests if an expression evaluates to an error, if so calls stopwarn otherwise does whatever is given as argument.

Usage

1
ifnerror(expr, noerror, error = "warn", silent = T)

Arguments

expr

expression to test for error.

noerror

expression to be called if no error.

error

one of 'warn' or 'stop', passed to stopwarn.

silent

logical, if TRUE (default) then error returned silently.

Details

Tests for an error or nerror (no error) from given expression. If an error is found then either returns NULL with warning or breaks code. If nerror then returns the given expression.

See Also

stopwarn

Examples

1
2
3
4
5
## Not run: 
ifnerror(1/2,print("Success"))
ifnerror(1/"a",print("Success"),"stop",silent = F)

## End(Not run)

RaphaelS1/RSmisc documentation built on June 7, 2019, 8:20 p.m.