Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Send Growl notifications from R (RStudio, R GUI or R console) - Requires growlnotify / Similar to https://goo.gl/dtP4eH
growl.notify <- function(msg = "Operation complete") {
in.osx <- (Sys.info()['sysname'] == "Darwin")
in.rstudio <- (Sys.getenv("RSTUDIO") == "1")
in.rgui <- (Sys.getenv("R_GUI_APP_REVISION") != "")
dir.notifier <- system("which growlnotify", intern = TRUE)
if (in.rstudio) { # hack to see if running in RStudio
title <- "RStudio"
}
if (in.rgui) { # running in R GUI app?
title <- "R"
}
# if running in RStudio or R GUI app use Growl otherwise use message()
if ((in.rstudio | in.rgui) & in.osx) {
system(paste(dir.notifier, "--appIcon", title, title, "-m '", msg, "'", sep = " "),
ignore.stdout = TRUE, ignore.stderr = TRUE, wait = FALSE)
} else {
message(msg)
}
}
# try it!
# if ((Sys.info()['sysname'] == "Darwin")) {devtools::source_gist("1867e024f74a80a736b1f5981349ed88")}
# system("sleep 10")
# growl.notify("Long op complete")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment