mercredi 8 juin 2011

Mettre en oeuvre Growlnotify dans r


Pour utiliser GrowlNotify dans r
D’abord l’installer:
http://growl.info/downloads#generaldownloads

Ensuite définir la variable $PATH pour un shell non interactif. Dans le terminal:
cd ~
sudo pico .bashrc
copier:
export PATH=/usr/local/bin:$PATH

ctrl+X pour quitter et sauver le fichier.

Ensuite dans r:
system("growlnotify -t 'R script info' -m 'Finished!' -a 'R'")

Et voilà.

Si le PATH n’est pas défini dans le .bashrc, il faut faire:
system("/usr/local/bin/growlnotify -t 'R script info' -m 'Finished!' -a 'R'")

Pour le lancer que sur Mac, j'ai créé cette fonction. Elle est disponible dans mon package phenology:


growlnotify <-
function(textinfo="", help=FALSE) {
if(help) {
cat("This function is used to send a notification to Mac user.\n")
cat("The syntax is growlnotify(textinfo='Done!')\n")

} else {
if (.Platform$OS.type=="unix") {
if (substr(.Platform$pkgType, 1, 3)=="mac") {
if (any(system("ls /usr/local/bin/", intern=TRUE)=="growlnotify")) {
system(paste("/usr/local/bin/growlnotify -t 'R script info' -m '", textinfo, "' -a 'R'", sep=""))
}
}
}
}
}