美文网首页
R里面的tryCatch

R里面的tryCatch

作者: qingmei_comeon | 来源:发表于2018-04-04 14:46 被阅读0次

转载自:https://blog.csdn.net/luoyexuge/article/details/49105299

(1)抓取错误

 tryCatch(libray(xx),error=function(e){print("出现错误")} )

当xx包出现错误时候就会执行error函数 ,把error的结果执行出来

(2)抓取错误和警告

tryCatch(libray(xx),warning = function(w){print("出现警告")},
               error=function(e){print("出现错误")} )

(3)finally最后都会执行,跟python和java类似

tryCatch(libray(xx),warning = function(w){print("出现警告")},
               error=function(e){print("出现错误")},
               finally={
                 print("导入ggplot2包")
                 library(ggplot2)
               }
)

相关文章

网友评论

      本文标题:R里面的tryCatch

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