Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Categories
Tags
In the age of smartphones, Notifications have become an integral part of life that Smart watches have started popping up to handle our notifications. Desktop Notification is a very good way of letting the user know about a task completion or some information. Say, your model has been running and at the end, you just send a notification of the AUC score. Wouldn’t it be nice to have? 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 & Loading
notifier
is currently available only on github, hence can be installed using the following code:
#install.packages("devtools") if devtools is not installed devtools::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:
Basic usage
notifier
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 World
As in every computer programming exercise, Let us begin with a simple Hello World notification message.
#composing the first notification message notify( title = "Here goes the Title", msg = c("Hello","World") )
Gives this notification (screenshot):
Slightly more useful
Now 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 notification notify( title = "World Clock", msg = c(paste0(" India - ", format(Sys.time(), format = "%H:%M:%S" ,tz = "Asia/Calcutta"),"\n", paste0("Singapore - ", format(Sys.time(), format = "%H:%M:%S" ,tz = "Asia/Singapore"),"\n")) ) )
Gives this notification (screenshot):
A Motivational Notification
As 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 notification library(randquotes) notify( title = "Quote of the Day", msg = c(randquote_simple()) )
Gives this notification (screenshot):
Further Improvement
This 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.
Summary
I 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.
Let us know in comments of what notification you’d like to try or you’ve tried!
Related Post
- CHAID vs. ranger vs. xgboost — a comparison
- Common Mistakes to Avoid When Learning to Code in Python
- Top Python Libraries for Machine Learning
- Get Popular Programming Languages from TIOBE Index using R
- How to make Seaborn Pairplot and Heatmap in R (Write Python in R)
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.