How can I make R send an alert if it encounters an error?

江枫思渺然 提交于 2020-02-25 07:58:09

问题


I currently enjoy receiving email notifications when my R scripts have finished running, thanks to the mail package.

However, I would like to know if it's possible to have R (or RStudio, or something else) notify me if a script fails to finish running because it has encountered an error? Email would be the best delivery method.

This would be extremely useful when I'm running code on a remote machine, or when I'm away from my computer.


回答1:


Get a pushbullet message: http://cran.r-project.org/web/packages/RPushbullet/index.html

Or send yourself an email: http://cran.r-project.org/web/packages/mailR/

And use tryCatch...

a <- tryCatch({
    source("your_script.R")
}, warning = function(w) {
    warning-handler-code
}, error = function(e) {
    send mail, pushbullet, etc...
}, finally = {
    cleanup
}


来源:https://stackoverflow.com/questions/28886696/how-can-i-make-r-send-an-alert-if-it-encounters-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!