my_blog
my_blog copied to clipboard
让 R 在完成任务时发送通知或者叮一声
2017-06-22
让 R 在完成任务时发送通知或者叮一声
Is there a way to make R beep/play a sound at the end of a script?
-
Throw a Beep
install.packages("beepr") library(beepr) beep()
The package is developped at GitHub.
Usage
beep(sound = 1, expr = NULL)
Arguments
sound
character string or number specifying what sound to be played by either specifying one of the built in sounds or specifying the path to a wav file. The default is 1. Possible sounds are:-
random
-
"ping"
-
"coin"
-
"fanfare"
-
"complete"
-
"treasure"
-
"ready"
-
"shotgun"
-
"mario"
-
"wilhelm"
-
"facebook"
-
"sword"
-
-
To get a message, you can use
notify-send
command:
system("notify-send \"R script finished running\"")
在 ~/.Rprofile
里添加:
notify <- function(){
cmd <- "notify-send"
system2(cmd, args="-i emblem-default 'R Message' 'Mission Complete!'")
}
beep <- function(){beepr::beep()}
这样以后执行需要长时间跑的命令时,如果你打算去打开网页看其他东西,直接在末尾放上 notify()
任务完成时桌面会弹出通知,如果你打算玩手机,beep()
会在任务完成是发出声音(在自习室或图书馆请插上耳机谢谢)。