Create Desktop Notifications from R to improve your Data Science Productivity

With this R package notifier, You can do that.

About notifier:notifier is an R package by the well-known Gábor Csárdi of RStudio.

notifier can be used to send desktop notifications from R, on macOS, Windows and Linux.

notifier works across platform (Windows / Mac/ Linux) but the following code has been written and tested on macOS High Sierra Machine.

notifier Installation & Loadingnotifier is currently available only on github, hence can be installed using the following code:#install.

packages("devtools") if devtools is not installeddevtools::install_github("gaborcsardi/notifier")We can load notifier into our current R session using the following code (just like any other R package).

library(notifier)How does it work?As described in the documentation, This is how the notification appears:On macOS, notifier uses the terminal-notifier tool, see https://github.

com/julienXX/terminal-notifierOn Linux and *BSD systems, including Solaris the notify-send command line tool is used.

This requires the libnotify-bin package on Ubuntu/Debian and similar systems, or the libnotify package on RedHat/CentOS/Fedora and similar systems.

On Windows 8 or newer Windows versions, notifier uses the toaster tool, see https://github.


On older Windows versions, notifier uses the notifu program, see https://www.



Basic usagenotifier is very minimal with one function to create a notification or as the function says, “notify“.

The function notify() takes the following three arguments:* title — Message title.

 * msg — Actual Notification Message.

 * image — Image, along with the message — optional.

Hello WorldAs in every computer programming exercise, Let us begin with a simple Hello World notification message.

#composing the first notification messagenotify( title = "Here goes the Title", msg = c("Hello","World") )Gives this notification (screenshot):Slightly more usefulNow that we have learnt how to send desktop notifications from R, let us try to make that notification with some meaning and use.

The one I could think of immediately is a world clock or Time of different countries.

The following is the code how we can do that.

This code simply takes the current system time and formats it in respective time zones.

Remember, the parameter msg takes only character type, hence we need to convert the date type to character type which by default happens as we have used paste0.

#composing a slightly complex and also useful notificationnotify( title = "World Clock", msg = c(paste0(" India – ", format(Sys.

time(), format = "%H:%M:%S" ,tz = "Asia/Calcutta"),".", paste0("Singapore – ", format(Sys.

time(), format = "%H:%M:%S" ,tz = "Asia/Singapore"),".")) ))Gives this notification (screenshot):A Motivational NotificationAs we have used base-R functions to create a slightly meaningful notification, let’s upgrade to a good notification that can motivate us — in the form of quotes.

For that, we will use another R package — randquotes.

#composing a different use-case notificationlibrary(randquotes)notify( title = "Quote of the Day", msg = c(randquote_simple()))Gives this notification (screenshot):Further ImprovementThis could be further improved by using Task Scheduler (on Windows) or Shell Scripting Automation (on Linux/Mac) to automate this notification at regular interval — like showing a Quote notification every morning.

SummaryI hope this post would have helped you learning about this R package notifier which makes sending Desktop notifications from R possible — which I didn’t even have an idea that could be possible.

The complete code used in this post is available on my github.

If you are interested in learning about handling web data, Check out this Datacamp Tutorial on Working with Web DataLet us know in comments of what notification you’d like to try or you’ve tried!This article was originally published on DS+.

. More details

Leave a Reply