Extending slackr

[This article was first published on Rstats on Reproducible Random Thoughts, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The slackr package, by Bob Rudis, 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:

  • Write to a channel (current) – slackr
    • Compile TeX snippets directly to a channel – tex_slackr
    • tex_slackr(xtable::xtable(mtcars))
    • This function uses the texPreview package to compile and generate the TeX output.
  • Read channel history (new) – history_slackr
  • Edit messages on a channel (new) – edit_slackr
  • Delete channel messages (new) – delete_slackr

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.


Progress Bars

Create text progress bar that is sent directly to a Slack channel.

progress_slackr <- function(x){
  s <- c(0,x,1)
  for(i in 1:length(s)){


This also solves a long standing problem of tracking the progress of parallel jobs on a server. We use slackr with the qapply package, which runs jobs on an Open Grid Scheduler/Engine. We can track each node


Attach on.exit expressions to any function in R and at the end of the original function an output will be sent to the Slack channel.

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.

ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)

#pass a message to Slack channel 'general'

lm.D9 <- slack_lm(weight ~ group)

#test that output keeps inheritance

#pass a message to Slack channel 'general' with a header message to begin output
header_msg='This is a message to begin')

lm.D9 <- slack_lm(weight ~ group)

#onexit with an expression that calls lm.plot
 par(mfrow = c(2, 2), oma = c(0, 0, 2, 0))
header_msg = 'This is a plot just for this output',
use_device = TRUE)

lm.D9 <- slack_lm(weight ~ group)

#clean up slack channel from examples
delete_slackr(count = 6,channel = '#general')

To leave a comment for the author, please follow the link and comment on their blog: Rstats on Reproducible Random Thoughts.

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)