title: Retry for-loop R loop if error
body: <p>I have an R For loop that downloads data from a server and adds result to table however, I sometimes get an error stopping the loop. If I tell it to redo the last download and continue, it works for another while before the next error. 
  The error isn't with code or data, but is random; sometimes it runs for 2.5 hours, other times it stops after 45 minutes downloading the <em>same data</em>.<br>
  Is there a way I could get my loop to take a step back if there is an error and retry? 
  eg. in</p>
  
  <pre><code>for (i in 1:1000){
      table[i,] &lt;- downloadfnc("URL", file = i)
  }
  </code></pre>
  
  <p>lets say I get an error while it was downloading i=500, all I do to fix is:    </p>
  
  <pre><code>for (i in 500:1000){
      i &lt;- i + 499     #since i starts at 1, 499+1=500
      table[i,] &lt;- downloadfnc("URL",file = i)
  }
  </code></pre>
  
  <p>then it downloads file"500" even though it got an error last time.
  is there a way I could automate it, so that if there is an error, it takes a step back (i-1) and retry it (perhaps with a few seconds delay)?  </p>
  
  <p>(been using R for only several weeks, so basic talk please)</p>