<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/send-desktop-notifications-from-r-in-windows-linux-and-mac/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/send-desktop-notifications-from-r-in-windows-linux-and-mac/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul></ul>
<p><strong>
<p>Categories</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/category/programming/" title="Permanent Link toProgramming" target="_blank">Programming</a></li>
</ol>
<p><strong>
<p>Tags</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/best-r-packages/" title="Permanent Link toBest R Packages" target="_blank">Best R Packages</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/rstats/" title="Permanent Link toR Programming" target="_blank">R Programming</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/tips-tricks/" title="Permanent Link toTips &amp; Tricks" target="_blank">Tips &amp; Tricks</a></li>
</ol>
<p>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 <code>notifier</code>, You can do that. </p>
<h2>About notifier:</h2>
<p><code><a rel="nofollow" href="https://github.com/gaborcsardi/notifier" target="_blank">notifier</a></code> is an R package by the well-known <a rel="nofollow" href="https://twitter.com/gaborcsardi" target="_blank">Gábor Csárdi</a> of RStudio. <code>notifier</code> can be used to send desktop notifications from R, on macOS, Windows and Linux. <code>notifier</code> works across platform (Windows / Mac/ Linux) but the following code has been written and tested on macOS High Sierra Machine.</p>
<h3>notifier Installation &amp; Loading</h3>
<p><code>notifier</code> is currently available only on github, hence can be installed using the following code:</p>
<pre>
#install.packages(&quot;devtools&quot;) if devtools is not installed
devtools::install_github(&quot;gaborcsardi/notifier&quot;)
</pre>
<p>We can load <code>notifier</code> into our current R session using the following code (just like any other R package).</p>
<pre>
library(notifier)
</pre>
<h3>How does it work? </h3>
<p>As described in the documentation, This is how the notification appears: </p>
<li>On macOS, notifier uses the terminal-notifier tool, see <a rel="nofollow" href="https://github.com/julienXX/terminal-notifier" target="_blank">https://github.com/julienXX/terminal-notifier</a></li>
<li>On 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.</li>
<li>On Windows 8 or newer Windows versions, notifier uses the toaster tool, see <a rel="nofollow" href="https://github.com/nels-o/toaster" target="_blank">https://github.com/nels-o/toaster</a>.</li>
<li>On older Windows versions, notifier uses the notifu program, see <a rel="nofollow" href="https://www.paralint.com/projects/notifu" target="_blank">https://www.paralint.com/projects/notifu</a>.</li>
<h3>Basic usage</h3>
<p><code>notifier</code> is very minimal with one function to create a notification or as the function says, “<b>notify</b>“. The function <code>notify()</code> takes the following three arguments:</p>
<p>* title – Message title.<br>
* msg – Actual Notification Message.<br>
* image – Image, along with the message – optional. </p>
<h3>Hello World</h3>
<p>As in every computer programming exercise, Let us begin with a simple Hello World notification message. </p>
<pre>
#composing the first notification message

notify(
  title = &quot;Here goes the Title&quot;,
  msg = c(&quot;Hello&quot;,&quot;World&quot;)
  )
  
</pre>
<p>Gives this notification (screenshot):</p>
<p><a rel="nofollow" href="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/10/helloworld_notification.png?ssl=1" target="_blank"><img sizes="(max-width: 694px) 100vw, 694px" src="https://i2.wp.com/datascienceplus.com/wp-content/uploads/2018/10/helloworld_notification.png?w=450&ssl=1" alt="" class="wp-image-17387" data-recalc-dims="1"></a></p>
<h3>Slightly more useful</h3>
<p>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.</p>
<p>This code simply takes the current system time and formats it in respective time zones. Remember, the parameter <code>msg</code> takes only character type, hence we need to convert the date type to character type which by default happens as we have used <code>paste0</code>.</p>
<pre>
#composing a slightly complex and also useful notification

notify(
  title = &quot;World Clock&quot;,
  msg = c(paste0(&quot; India - &quot;, format(Sys.time(), format = &quot;%H:%M:%S&quot; ,tz = &quot;Asia/Calcutta&quot;),&quot;\n&quot;,
                 paste0(&quot;Singapore - &quot;, format(Sys.time(), format = &quot;%H:%M:%S&quot; ,tz = &quot;Asia/Singapore&quot;),&quot;\n&quot;))
          )
)

</pre>
<p>Gives this notification (screenshot):</p>
<p><a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/10/worldclock_R_notification.png?ssl=1" target="_blank"><img sizes="(max-width: 690px) 100vw, 690px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/10/worldclock_R_notification.png?w=450&ssl=1" alt="" class="wp-image-17389" data-recalc-dims="1"></a></p>
<h3>A Motivational Notification</h3>
<p>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 – <a rel="nofollow" href="https://cran.r-project.org/web/packages/randquotes/index.html" target="_blank">randquotes</a>. </p>
<pre>
#composing a different use-case notification


library(randquotes)
notify(
  title = &quot;Quote of the Day&quot;,
  msg = c(randquote_simple())
)


</pre>
<p>Gives this notification (screenshot):</p>
<p><a rel="nofollow" href="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/10/quote_notification.png?ssl=1" target="_blank"><img sizes="(max-width: 678px) 100vw, 678px" src="https://i1.wp.com/datascienceplus.com/wp-content/uploads/2018/10/quote_notification.png?w=450&ssl=1" alt="" class="wp-image-17390" data-recalc-dims="1"></a></p>
<h3>Further Improvement</h3>
<p>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. </p>
<h3>Summary</h3>
<p>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 <a rel="nofollow" href="https://github.com/amrrs/blogpost_codes/blob/master/notifier_desktop_notifications.R" target="_blank">my github</a>. </p>
<p>Let us know in comments of what notification you’d like to try or you’ve tried! </p>
<p><strong>
<p>Related Post</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/chaid-vs-ranger-vs-xgboost-a-comparison/" title="Permanent Link toCHAID vs. ranger vs. xgboost — a comparison" target="_blank">CHAID vs. ranger vs. xgboost — a comparison</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/common-mistakes-to-avoid-when-learning-to-code-in-python/" title="Permanent Link toCommon Mistakes to Avoid When Learning to Code in Python" target="_blank">Common Mistakes to Avoid When Learning to Code in Python</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/top-python-libraries-for-machine-learning/" title="Permanent Link toTop Python Libraries for Machine Learning" target="_blank">Top Python Libraries for Machine Learning</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/get-popular-programming-languages-from-tiobe-index-using-r/" title="Permanent Link toGet Popular Programming Languages from TIOBE Index using R" target="_blank">Get Popular Programming Languages from TIOBE Index using R</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/how-to-make-seaborn-pairplot-and-heatmap-in-r-write-python-in-r/" title="Permanent Link toHow to make Seaborn Pairplot and Heatmap in R (Write Python in R)" target="_blank">How to make Seaborn Pairplot and Heatmap in R (Write Python in R)</a></li>
</ol>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://datascienceplus.com/send-desktop-notifications-from-r-in-windows-linux-and-mac/"> R Programming – DataScience+</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/brKk6LnqOwY" height="1"></a></div>