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