Sending web-based notifications via R

When running timely R jobs, you are now able to send yourself a notification for when the job is completed. Via a mobile application downloaded on your phone, R can send values and messages to your mobile device. There are other possible uses for this application. This is just a simple example of how to send yourself a notification using IF and R. This introduction is based on the full tutorial by Brian Connelly. Visit Connecting R to everything with IFTTT for more information on how to configure the ‘Maker’ channel.

Implementation

First, create an IFTTT.com account and follow this tutorial for setting up the ‘Maker’ channel on the web.

After installation and account creation, create a new recipe using the ‘Maker’ channel.

  1. Download the ‘IF’ application on your mobile device. Android

  1. Click on the recipes icon and then on the settings gear.

  1. Select the ‘Maker’ channel.

  1. Copy your secret key to your R session.

Note: Your secret key can be saved as an R environment variable in the ~/.Renviron (~/_Renviron for Windows) file.

  1. Back in R, use the httr package to send URL requests. First create a basic url for the maker channel on IFTTT.com.
library(httr)

my_event <- 'r_status'
my_key <- 'mytopsecretkey'

maker_url <- paste("https://maker.ifttt.com/trigger", my_event, "with/key", my_key, sep = "/")

Send a message with no data

The POST function from the httr package allows you to send bits of information via the web from R.

httr::POST(maker_url)

Send arbitrary values

httr::POST(maker_url, body=list(value1 = "bonjour", value2="le monde", value3 = 7))

Send results

data(mtcars)
httr::POST(maker_url, body=list(value1="MPG and WT means", 
                                  value2 = mean(mtcars$mpg), 
                                  value3 = mean(mtcars$wt)))