Note that there are some explanatory texts on larger screens.

plurals
  1. POskip to next value of loop upon error in R [tryCatch]
    text
    copied!<p>I've read a few other SO questions about <code>tryCatch</code> and cuzzins, as well as the documentation:</p> <ul> <li><a href="https://stackoverflow.com/questions/2622777/exception-handling-in-r">Exception handling in R</a></li> <li><a href="https://stackoverflow.com/questions/2158780/r-catching-an-error-and-then-branching-logic">catching an error and then branching logic</a></li> <li><a href="https://stackoverflow.com/questions/3903157/how-can-i-check-whether-a-function-call-results-in-a-warning">How can I check whether a function call results in a warning?</a></li> <li><a href="http://r.789695.n4.nabble.com/problems-with-plots-in-loop-corrected-Email-td3597451.html" rel="noreferrer">Problems with Plots in Loop</a></li> </ul> <p>but I still don't understand.</p> <p>I'm running a loop and want to skip to <code>next</code> if any of a few kinds of errors occur:</p> <pre><code>for (i in 1:39487) { #ERROR HANDLING this.could.go.wrong &lt;- tryCatch( attemptsomething(), error=function(e) next ) so.could.this &lt;- tryCatch( doesthisfail(), error=function(e) next ) catch.all.errors &lt;- function() { this.could.go.wrong; so.could.this; } catch.all.errors; #REAL WORK useful(i); fun(i); good(i); } #end for </code></pre> <p><em>(by the way, there is no documentation for <code>next</code> that I can find)</em></p> <p>When I run this, <code>R</code> honks:</p> <pre><code>Error in value[[3L]](cond) : no loop for break/next, jumping to top level </code></pre> <p>What basic point am I missing here? The <code>tryCatch</code>'s are clearly within the <code>for</code> loop, so why doesn't <code>R</code> know that?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload