search for: abunchofcod

Displaying 3 results from an estimated 3 matches for "abunchofcod".

Did you mean: abunchofcode
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
1
[tryExcept] New try Function
...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 bunch of code > # Some value to be stored in res > }) > The only difference is that now "#abunchofcode" is run from inside a > function, which means you're working in a different environment, and if you > want to assign values to other variables you need to use <<- or assign. > For a modified function, I think it would be nice if there's a way to > supply an expressio...
2018 Nov 23
0
[tryExcept] New try Function
...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 bunch of code # Some value to be stored in res }) The only difference is that now "#abunchofcode" is run from inside a function, which means you're working in a different environment, and if you want to assign values to other variables you need to use <<- or assign. For a modified function, I think it would be nice if there's a way to supply an expression instead of a funct...