title: Run until no error occurred
body: <p>I want to execute a function which uses an internet connection to grep some online data. Because the connection is not very stable, it needs several attempts to run the function successfully. 
  Therfore I want to repeat or loop the function until it worked and also save the results.</p>
  
  <p>tryCatch seems to be a suitable function but so far I did not find a way to solve the problem. 
  This is the function:</p>
  
  <pre><code>annotations(snp = 'rs1049434', output = 'snpedia') 
  </code></pre>
  
  <p>and sometimes this error occur:</p>
  
  <pre><code>Error in annotations(snp = "rs1049434", output = "snpedia") : 
    server error: (502) Bad Gateway
  </code></pre>
  
  <p>The basic code schematically:</p>
  
  <pre><code>while( tmp == F){
    ifelse(result &lt;- function worked, tmp &lt;- T, tmp &lt;- F)}
  </code></pre>
  
  <p>And I need the output <code>result</code> which is a data.frame. </p>
  
  <p>ANSWER (see the link in the comment from nicola):</p>
  
  <pre><code>bo=0
  while(bo!=10){
    x = try(annotations(snp = 'rs1049434', output = 'snpedia'),silent=TRUE)
    if (class(x)=="try-error") {
      cat("ERROR1: ", x, "\n")
      Sys.sleep(1)
      print("reconntecting...")
      bo &lt;- bo+1
      print(bo)
    } else
    break 
  }
  </code></pre>