slackr provides a set of tools for making it easier to send messages,
data, alerts, etc. directly from R to Slack. You can use this package to
send well-formatted output from R to all teammates (or to specific
individuals) at the same time with little effort. You can send text, R
function output, images from the current graphics device and
R objects (as R data files), rendered LaTeX expressions, and uploaded
# CRAN version install.packages("slackr") # Development version devtools::install_github("mrkaye97/slackr")
3.0.0+ removes all references to
v2.4.0) in favor of
token. There have also been
significant changes to how
slackr_bot handle errors. See
the changelog for
2.4.0+ now allows users to choose between using a bot token
and a user token. See below for details and check the changelog
NEWS.md) for more changes.
There are three ways of interfacing with
slackr that provide
significantly different functionality:
Creating a single-channel bot
Using only a webhook to send messages to a channel
Creating a fully-functional multi-channel bot
Creating a bot user to send messages to multiple channels, including plots, tables, files, etc. as well as deleting messages, reading the channels in a workspace, etc.
Using a user token to send messages from a specific user’s account
Similar to the fully-scoped bot token, but connected to the account of a single user. This approach is not recommended in production settings – or any settings where a token needs to be shared – but it can be useful for one-off Slack messages as it lets users send data as themselves as opposed to through a bot.
In most cases, we recommend
Option 1 above. This requires the fewest
permissions and is the simplest to set up, and will allow basic
messaging to a specific channel.
See the vignettes for setup instructions.
The vignettes contain setup instructions and example usage:
- Option 1 setup:
vignette('scoped-bot-setup', package = 'slackr')
- Option 2 setup:
vignette('webhook-setup', package = 'slackr')
vignette('using-slackr', package = 'slackr')
Important Note: The setup process for
Option 2 and
Option 3 are
roughly the same, with only slightly differing scopes.
Config File Setup
slackr_setup() function will try to read setup values from a
~/.slackr (you can change the default) configuration file, which may
be easier and more secure than passing them in manually (plus, will
allow you to have multiple
slackr configurations for multiple
The file is in Debian Control File (DCF) format since it really doesn’t
need to be JSON and R has a handy
read.dcf() function since that’s
DESCRIPTION files are coded in.
Here’s the basic format for the configuration file:
token: xox*-<your app's token> channel: #general username: slackr incoming_webhook_url: https://hooks.slack.com/services/XXXXX/XXXXX/XXXXX icon_emoji: 'boom'
slackr 2.3.0, you can create a config file with
create_config_file() instead of setting it up manually. See the docs
You can also change the default emoji icon (from the one you setup at
integration creation time) with
Many thanks to:
- Bob Rudis
- Jay Jacobs
- David Severski
- Quinn Weber
- Konrad Karczewski
- Ed Niles
- Rick Saporta
- Jonathan Sidi
- Matt Kaye
- Xinye Li
- Andrie de Vries
for their contributions to the package!
- Depending on your scopes,
slackrcould quietly fail (i.e. not throw an error, but also not post anything to your channel). If this happens, try explicitly adding the app you’re trying to have
slackrpost as to the channel you want in your Slack workspace with
/invite @your_app_nameor make sure you have