Displaying 3 results from an estimated 3 matches for "tryexcept".
2018 Nov 23
1
[tryExcept] New try Function
...work, as you can return a value. However, sometimes it is useful
to assign 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(exp...
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
2018 Nov 23
0
[tryExcept] New try Function
Hi Ernest,
To start: I don't see an attachment, I think they're not (always) allowed on this mailing-list. If you want to send something, text is your safest bet.
But regarding the issue of tryCatch: I think you're not fully using what it already can do. In almost all circumstances I've encountered the following works fine:
res <- tryCatch(expr, error = function(cond) {
# a