[R] Find exit status inside on.exit

McGehee, Robert Robert.McGehee at geodecapital.com
Fri Feb 10 18:07:29 CET 2012


Hello,
Does anyone know if it is possible to find out whether a calling function exited with an error or not inside of an on.exit() call? I'd like to use the same error cleanup function inside of several functions, and for aesthetic reasons would prefer not to surround the body of all of these function with a tryCatch.

Something like this:

isError <- function() {
        parentError <- ???
        if (!parentError) cat("No errors here!\n")
}

X <- function() {
        on.exit(isError())
        1+1
}

> X()
[1] 2
No errors here!

Thanks,
Robert

Robert McGehee, CFA
Geode Capital Management, LLC
One Post Office Square, 28th Floor | Boston, MA | 02109
Direct: (617)392-8396

This e-mail, and any attachments hereto, are intended fo...{{dropped:10}}



More information about the R-help mailing list