Learn R Programming

plyr (version 1.5.2)

failwith: Fail with specified value.

Description

Fail with specified value.

Usage

failwith(default, f, quiet=FALSE)

Arguments

default
default value
f
function
quiet
all error messages be suppressed?

Value

  • a function

Details

Modify a function so that it returns a default value when there is an error.

See Also

try_default

Examples

Run this code
f <- function(x) if (x == 1) stop("Error!") else 1
f(1)
f(2)

safef <- failwith(NULL, f)
safef(1)
safef(2)

Run the code above in your browser using DataLab