美文网首页R - tips
for循环中遇到error如何继续运行程序

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

作者: 董八七 | 来源:发表于2018-08-05 21:32 被阅读8次

抓取数据时遇到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如何继续运行程序

    本文链接:https://www.haomeiwen.com/subject/borivftx.html