failWith: Utility function to try and fail with grace.

View source: R/utilities.R

failWithR Documentation

Utility function to try and fail with grace.

Description

Inspired from one of Hadley's functions (in plyr or something?)

Usage

failWith(
  default = NULL,
  expr,
  frame = parent.frame(),
  message = geterrmessage(),
  silent = FALSE,
  file = stderr()
)

Arguments

default

the value to return if expr fails

expr

the expression to take a shot at

frame

the frame to evaluate the expression in

message

the error message to display if expr fails. Deafults to base::geterrmessage()

silent

if TRUE, sends the error message to msg()

file

where msg sends the message

Value

the result of expr if successful, otherwise default value.

Examples

# look, this doesn't throw an error, it just returns NULL
x <- failWith(NULL, stop("no error, just NULL"), silent = TRUE)

lianos/sparrow documentation built on Nov. 22, 2024, 11:23 p.m.