如果R遇到错误,如何使R发送警报? [英] How can I make R send an alert if it encounters an error?
问题描述
由于 mail
软件包,我目前喜欢在R脚本运行完毕后收到电子邮件通知。
I currently enjoy receiving email notifications when my R scripts have finished running, thanks to the mail
package.
但是,我想知道是否有可能让R(或RStudio或其他东西)通知我,如果脚本因为遇到脚本失败而无法完成运行错误?电子邮件将是最好的传递方法。
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.
当我在远程计算机上运行代码或不在计算机上时,这将非常有用。 / p>
This would be extremely useful when I'm running code on a remote machine, or when I'm away from my computer.
推荐答案
获取推送消息: http://cran.r-project.org/web/packages/RPushbullet/index.html
或给自己发送电子邮件: http://cran.r-project.org/ web / packages / mailR /
Or send yourself an email: http://cran.r-project.org/web/packages/mailR/
并使用tryCatch ...
And use tryCatch...
a <- tryCatch({
source("your_script.R")
}, warning = function(w) {
warning-handler-code
}, error = function(e) {
send mail, pushbullet, etc...
}, finally = {
cleanup
}
这篇关于如果R遇到错误,如何使R发送警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!