Skip to content

Commit

Permalink
Allow fail with to take function names. Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Mar 10, 2009
1 parent ff4269d commit df62838
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plyr 0.1.6 (2008-XX-XX) ---------------------------------------------------

* use list names where present
* failwith now accepts a function name, as well as a function itself

plyr 0.1.5 (2008-02-23) ---------------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions R/helper-try.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
# @argument should all error messages be suppressed?
# @value a function
# @seealso \code{\link{try_default}}
#X \dontrun{
#X f <- function(x) if (x == 1) stop("Error!") else 1
#X f(1)
#X f(2)
#X }
#X
#X safef <- failwith(NULL, f)
#X safef(1)
#X safef(2)
failwith <- function(default = NULL, f, quiet = FALSE) {
f <- match.fun(f)
function(...) try_default(f(...), default, quiet = quiet)
}

Expand Down

0 comments on commit df62838

Please sign in to comment.