转载自: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)
}
)