search for: dotryexcept

Displaying 2 results from an estimated 2 matches for "dotryexcept".

2018 Nov 23
1
[tryExcept] New try Function
...ign several variables when an error occurs. You could do it with <<-, but I prefer to reduce it's usage unless completely necessary. I guess that the attachment was missed in the moderation. Here it is the function: tryExcept <- function (expr, except = {}) { doTryExcept <- function(expr, parentenv) { .Internal(.addCondHands("error", list(NULL), parentenv, environment(), FALSE)) expr } parentenv <- parent.frame() doTryExcept(return(expr), parentenv) invisible(except) } As you can see, the tryExcept functi...
2018 Nov 22
2
[tryExcept] New try Function
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