Skip to content
Browse files

Allow fail with to take function names. Add examples

  • Loading branch information...
1 parent ff4269d commit df6283841b5f38ad74eb419336ecdf2ffac2f5aa @hadley committed Mar 10, 2009
Showing with 11 additions and 0 deletions.
  1. +1 −0 NEWS
  2. +10 −0 R/helper-try.r
View
1 NEWS
@@ -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) ---------------------------------------------------
View
10 R/helper-try.r
@@ -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)
}

0 comments on commit df62838

Please sign in to comment.
Something went wrong with that request. Please try again.