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

library(devtools)
install_github("hrbrmstr/slackr")


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

Very Cool!

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:

2. Open the project in RStudio

3. Open the R file names slackr_utils.R

4. In the function named slackr_ims the last line (line 117) is something like dplyr::left_join( %some stuff% )

5. Replace this line with suppressWarnings( merge(users, ims, by.x=”id”, by.y=‘user’) )

6. The compile and install the package as:

require(devtools)