<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/extending-slackr/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://yonicd.netlify.com/post/slackr/"> Rstats on Reproducible Random Thoughts</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>The <a rel="nofollow" href="https://github.com/hrbrmstr/slackr" target="_blank">slackr</a> package, by <a rel="nofollow" href="https://rud.is/b/" target="_blank">Bob Rudis</a>, contains functions that make it possible to interact with the Slack messaging platform. The great part of Slack is that it has mobile devices application interface. We take advantage of this by extending slackr’s interaction with with the server:</p>
<ul>
<li><strong>Write</strong> to a channel (current) – <code>slackr</code>
<ul>
<li>Compile TeX snippets directly to a channel – <code>tex_slackr</code></li>
<li><code>tex_slackr(xtable::xtable(mtcars))</code></li>
<li>This function uses the <a rel="nofollow" href="https://github.com/metrumresearchgroup/texPreview" target="_blank">texPreview</a> package to compile and generate the TeX output.</li>
</ul>
</li>
<li><strong>Read</strong> channel history (new) – <code>history_slackr</code></li>
<li><strong>Edit</strong> messages on a channel (new) – <code>edit_slackr</code></li>
<li><strong>Delete</strong> channel messages (new) – <code>delete_slackr</code></li>
</ul>
<p>This lets us interact with R and Slack in new ways, by getting active updates on long simulations directly to your (and your team’s) mobile device and multitask away from your computer.</p>
<pre><code>devtools::install_github('hrbrmstr/slackr')</code></pre>
<div>
<h2>Progress Bars</h2>
<p>Create text progress bar that is sent directly to a Slack channel.</p>
<p><img src="https://i2.wp.com/raw.githubusercontent.com/yonicd/blog/master/img/slackr/slackr_progress.gif?w=456&ssl=1" data-recalc-dims="1" height="auto"></p>
<pre><code>progress_slackr &lt;- function(x){
  text_slackr('0%')
  s &lt;- c(0,x,1)
  for(i in 1:length(s)){
    Sys.sleep(0.5)
    edit_slackr(sprintf('%s%%',round(100*i/length(s),1)))
  }
  Sys.sleep(0.5)
}

set.seed(1234)
progress_slackr(sort(runif(10)))</code></pre>
<p>This also solves a long standing problem of tracking the progress of parallel jobs on a server. We use slackr with the <a rel="nofollow" href="https://bitbucket.org/metrumrg/qapply/src" target="_blank">qapply</a> package, which runs jobs on an Open Grid Scheduler/Engine. We can track each node</p>
<p><img src="https://i1.wp.com/raw.githubusercontent.com/yonicd/blog/master/img/slackr/slackr_qapply.gif?w=456&ssl=1" data-recalc-dims="1"></p>
</div>
<div>
<h2>Onexit</h2>
<p>Attach <code>on.exit</code> expressions to any function in R and at the end of the original function an output will be sent to the Slack channel.</p>
<p>This is useful for letting you know when a simulation is done, but also to be able to send to the Slack channel a relevant summary to see that the simulation did as intended.</p>
<p><img src="https://i0.wp.com/raw.githubusercontent.com/yonicd/blog/master/img/slackr/slackr_expr.gif?w=456&ssl=1" data-recalc-dims="1"></p>
<pre><code>ctl &lt;- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt &lt;- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group &lt;- gl(2, 10, 20, labels = c(&quot;Ctl&quot;,&quot;Trt&quot;))
weight &lt;- c(ctl, trt)

#pass a message to Slack channel 'general'
register_onexit(lm,'bazinga!',channel=&quot;#general&quot;)

lm.D9 &lt;- slack_lm(weight ~ group)

#test that output keeps inheritance
summary(lm.D9)

#pass a message to Slack channel 'general' with a header message to begin output
register_onexit(lm,'bazinga!',
channel=&quot;#general&quot;,
header_msg='This is a message to begin')

lm.D9 &lt;- slack_lm(weight ~ group)

#onexit with an expression that calls lm.plot
register_onexit(lm,{
 par(mfrow = c(2, 2), oma = c(0, 0, 2, 0))
 plot(z)
},
channel=&quot;#general&quot;,
header_msg = 'This is a plot just for this output',
use_device = TRUE)

lm.D9 &lt;- slack_lm(weight ~ group)

#clean up slack channel from examples
delete_slackr(count = 6,channel = '#general')</code></pre>
</div>
	<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://yonicd.netlify.com/post/slackr/"> Rstats on Reproducible Random Thoughts</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/3kNdpWaB6U0" height="1"></a></div>