[Rd] [tryExcept] New try Function

Ernest Benedito ebenedito@ @ending from gm@il@com
Thu Nov 22 23:51:31 CET 2018


Hi everyone,

When dealing with errors, sometimes I want to run a bunch of code when an error occurs.
For now I usually use a structure such as:

res <- tryCatch(expr, error = function(cond) cond) # or try(expr)

if (inherits(res, “error”)) # or inherits(res, “try-error”)
  # a bunch of code

I though it would be useful to have a function that does this naturally, so I came up with the attached function.

I would be glad to hear your insights and if you think it would make sense to add this function to R.

Best regards,
Ernest


More information about the R-devel mailing list