R 运行直到没有错误发生

R 运行直到没有错误发生,r,function,try-catch,R,Function,Try Catch,我想执行一个函数,它使用internet连接来grep一些在线数据。因为连接不是很稳定,所以需要多次尝试才能成功运行该函数。 因此,我想重复或循环函数,直到它工作,并保存结果 tryCatch似乎是一个合适的函数,但到目前为止,我还没有找到解决问题的方法。 这就是功能: annotations(snp = 'rs1049434', output = 'snpedia') 有时会出现这种错误: Error in annotations(snp = "rs1049434", output = "

我想执行一个函数,它使用internet连接来grep一些在线数据。因为连接不是很稳定,所以需要多次尝试才能成功运行该函数。 因此,我想重复或循环函数,直到它工作,并保存结果

tryCatch似乎是一个合适的函数,但到目前为止,我还没有找到解决问题的方法。 这就是功能:

annotations(snp = 'rs1049434', output = 'snpedia') 
有时会出现这种错误:

Error in annotations(snp = "rs1049434", output = "snpedia") : 
  server error: (502) Bad Gateway
基本代码示意图如下:

while( tmp == F){
  ifelse(result <- function worked, tmp <- T, tmp <- F)}

您可能会发现这很有用:那
tryCatch
代码是什么样子的?
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 <- bo+1
    print(bo)
  } else
  break 
}