Skip to content

Commit f3b14d1

Browse files
committed
ERRVL*() functions if not given any non-erroring expressions now throw the last error rather than a generic message.
fixes #41
1 parent 86fc981 commit f3b14d1

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

R/misc.utilities.R

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ ERRVL <- function(...){
510510
x <- eval(if(inherits(x, "try-error")) do.call(substitute, list(e, list(.=x))) else e, parent.frame())
511511
if(!inherits(x, "try-error")) return(x)
512512
}
513-
stop("No non-error expressions passed.")
513+
stop(attr(x, "condition"))
514514
}
515515

516516
#' @rdname ERRVL
@@ -527,9 +527,9 @@ ERRVL <- function(...){
527527
#' @export
528528
ERRVL2 <- function(...){
529529
for(e in eval(substitute(alist(...)))) # Lazy evaluate. (See http://adv-r.had.co.nz/Computing-on-the-language.html .)
530-
tryCatch(return(eval(e, parent.frame())),
531-
error = function(err){})
532-
stop("No non-error expressions passed.")
530+
err <- tryCatch(return(eval.parent(e)),
531+
error = function(err) err)
532+
stop(err)
533533
}
534534

535535
#' @rdname ERRVL
@@ -551,14 +551,13 @@ ERRVL2 <- function(...){
551551
#'
552552
#' @export
553553
ERRVL3 <- function(...){
554-
x <- NULL
554+
err <- NULL
555555
for(e in eval(substitute(alist(...)))) # Lazy evaluate. (See http://adv-r.had.co.nz/Computing-on-the-language.html .)
556-
x <- tryCatch(
557-
return(eval(if(!is.null(x)) do.call(substitute, list(e, list(.=x)))
558-
else e,
559-
parent.frame())),
556+
err <- tryCatch(
557+
return(eval.parent(if (!is.null(err)) do.call(substitute, list(e, list(. = err)))
558+
else e)),
560559
error = function(err) err)
561-
stop("No non-error expressions passed.")
560+
stop(err)
562561
}
563562

564563
#' Optionally test code depending on environment variable.

0 commit comments

Comments
 (0)