Output R expressions to a Slack channel/user

Share:

Description

Takes an expr, evaluates it and sends the output to a Slack chat destination. Useful for logging, messaging on long compute tasks or general information sharing.

Usage

1
2
3
4
5
6
7
8
9
slackr_msg(txt = "", channel = Sys.getenv("SLACK_CHANNEL"),
  username = Sys.getenv("SLACK_USERNAME"),
  icon_emoji = Sys.getenv("SLACK_ICON_EMOJI"),
  api_token = Sys.getenv("SLACK_API_TOKEN"), ...)

slackrMsg(txt = "", channel = Sys.getenv("SLACK_CHANNEL"),
  username = Sys.getenv("SLACK_USERNAME"),
  icon_emoji = Sys.getenv("SLACK_ICON_EMOJI"),
  api_token = Sys.getenv("SLACK_API_TOKEN"), ...)

Arguments

txt

text message to send to Slack. If a character vector of length > 1 is passed in, they will be combined and separated by newlines.

channel

which channel to post the message to (chr)

username

what user should the bot be named as (chr)

icon_emoji

what emoji to use (chr) "" will mean use the default

api_token

your full slack.com API token

...

other arguments passed to the Slack API chat.postMessage call

Details

By default, everyting but expr will be looked for in a "SLACK_" environment variable. You can override or just specify these values directly instead, but it's probably better to call slackrSetup first.

Note

You need a https://www.slack.com account and will also need to setup an API token https://api.slack.com/ Also, you can pass in add_user=TRUE as part of the ... parameters and the Slack API will post the message as your logged-in user account (this will override anything set in username)

See Also

slackr_setup, slackr_bot, dev_slackr, save_slackr, slackr_upload

Examples

1
2
3
4
5
## Not run: 
slackr_setup()
slackr_msg("Hi")

## End(Not run)