Extending slackr

Follow @hrbrmstr Star Issue
CRAN_Status_Badge downloads

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 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.

devtools::install_github('hrbrmstr/slackr')

Progress Bars

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

progress_slackr <- function(x){
  text_slackr('0%')
  s <- 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)))

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

Onexit

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'
register_onexit(lm,'bazinga!',channel="#general")

lm.D9 <- 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="#general",
header_msg='This is a message to begin')

lm.D9 <- 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="#general",
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')
comments powered by Disqus