for循环中遇到error如何继续运行程序

抓取数据时遇到error程序停止是件恼人的事,因为你不知道什么时候会停止,R也不会有提示。能否跳过error继续运行程序呢?

先给代码,主要是利用函数tryCatch实现的。

for (i in 1:length(vector)) {
  tryCatch({
  print(i)
  grant_ex(vector[i], dir_name="intro")
}, error=function(e){cat("#---数据库不存在相应记录!\n")})
}

from https://stackoverflow.com/questions/14748557/skipping-error-in-for-loop

你可能感兴趣的:(for循环中遇到error如何继续运行程序)