为了完整性,这里有一个函数,您可以将其用作任务回调,以自动为任何运行时间超过5秒的顶级命令生成系统通知.
# devtools::install_github("gaborcsardi/notifier")
notify_long_running <- function(second_cutoff = 5) {
last <- proc.time()[1]
function(expr, value, ok, visible) {
duration <- proc.time()[1] - last
if (duration > second_cutoff) {
notifier::notify(msg = paste0(collapse = " ", deparse(expr)),
title = sprintf("Completed in %.02f (s)", duration))
}
last <<- proc.time()[1]
TRUE
}
}
addTaskCallback(notify_long_running())
Run Code Online (Sandbox Code Playgroud)