Collab <- Slack + R
I just ran across an R package that allows you to integrate your R workflow into the Slack environment. Really cool. Below I show how to set it up and to post output of your analyses to slack channels for your team as well as to register notifications.
First things first, I recommend installing the latest version from the github repository.
Now you have to set up a config file. I think it looks for it in ~/.slackr It is a normal Debian Control File (DCF) format. Here is my example one:
api_token: xoxp-XXXXXXXXXXX-XXXXXXXXX-XXXXXXXXXX-XXXXXXXXX channel: #r username: rodney incoming_webhook_url: https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXX
You need to get the api_token and the incoming_webhook_url from slack itself. Once you have that file saved, when you want to setup the slackr environment, you load it in and can send messages such as:
require(slackr) slackr_setup() slackr("This is an incoming piece of text from RStudio")
Which results in the following in my #r slack channel:
There is also a provision for sending output graphics like ggplot objects. Here is an example of heterozygosity in the Arapat data set.
library(gstudio) library(ggplot2) data(arapat) he <- genetic_diversity(arapat,mode="He") p <- ggplot( he, aes(x=Locus, y=He)) + geom_bar(stat="identity") + theme_bw() ggslack(p)
Which directly uploads the image to the channel as:
There is a slight problem though. The current version of the slackr library has an error in it associated with (perhaps) a recent change in the Slack API that has not been fixed by the developer.
For me to get this to work, I had to compile the package myself after making the following change in one file. To fix it, do the following:
Download (or checkout) the repository from github at: https://github.com/hrbrmstr/slackr
Open the project in RStudio
Open the R file names slackr_utils.R
In the function named slackr_ims the last line (line 117) is something like dplyr::left_join( %some stuff% )
Replace this line with suppressWarnings( merge(users, ims, by.x=”id”, by.y=‘user’) )
The compile and install the package as:
require(devtools) load_all() build() install()
It should work just fine.
Hopefully, on the next time that this package is updated by the author, the left_join() problem will have been resolved. This issue had been marked as “resolved” in the github issues a while back but apparently not pushed to the repository.