Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

让 R 在完成任务时发送通知或者叮一声 #10

Open
JackieMium opened this issue Mar 9, 2018 · 1 comment
Open

让 R 在完成任务时发送通知或者叮一声 #10

JackieMium opened this issue Mar 9, 2018 · 1 comment
Labels
Code Talk is chip, show me the code Linux Linux related R R related
Milestone

Comments

@JackieMium
Copy link
Owner

2017-06-22

让 R 在完成任务时发送通知或者叮一声

Is there a way to make R beep/play a sound at the end of a script?

  1. 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:

    1. random

    2. "ping"

    3. "coin"

    4. "fanfare"

    5. "complete"

    6. "treasure"

    7. "ready"

    8. "shotgun"

    9. "mario"

    10. "wilhelm"

    11. "facebook"

    12. "sword"

  2. To get a message, you can use notify-send command:

system("notify-send \"R script finished running\"")
@JackieMium JackieMium added the R R related label Mar 9, 2018
@JackieMium JackieMium added this to the Migration milestone Mar 9, 2018
@JackieMium
Copy link
Owner Author

~/.Rprofile 里添加:

notify <- function(){
	cmd <- "notify-send"
	system2(cmd, args="-i emblem-default 'R Message' 'Mission Complete!'")
}

beep <- function(){beepr::beep()}

这样以后执行需要长时间跑的命令时,如果你打算去打开网页看其他东西,直接在末尾放上 notify() 任务完成时桌面会弹出通知,如果你打算玩手机,beep() 会在任务完成是发出声音(在自习室或图书馆请插上耳机谢谢)。

@JackieMium JackieMium added Linux Linux related Code Talk is chip, show me the code labels Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Code Talk is chip, show me the code Linux Linux related R R related
Projects
None yet
Development

No branches or pull requests

1 participant