I've read a few other SO questions about tryCatch
and cuzzins, as well as the documentation:
- Exception handling in R
- catching an error and then branching logic
- How can I check whether a function call results in a warning?
- Problems with Plots in Loop
but I still don't understand.
I'm running a loop and want to skip to next
if any of a few kinds of errors occur:
for (i in 1:39487) {
# EXCEPTION HANDLING
this.could.go.wrong <- tryCatch(
attemptsomething(),
error=function(e) next
)
so.could.this <- tryCatch(
doesthisfail(),
error=function(e) next
)
catch.all.errors <- function() { this.could.go.wrong; so.could.this; }
catch.all.errors;
#REAL WORK
useful(i); fun(i); good(i);
} #end for
(by the way, there is no documentation for next
that I can find)
When I run this, R
honks:
Error in value[[3L]](cond) : no loop for break/next, jumping to top level
What basic point am I missing here? The tryCatch
's are clearly within the for
loop, so why doesn't R
know that?