Skip to content

Instantly share code, notes, and snippets.

@dalejbarr
Last active August 29, 2015 14:23
Show Gist options
  • Save dalejbarr/da127ab789f2ada3998e to your computer and use it in GitHub Desktop.
Save dalejbarr/da127ab789f2ada3998e to your computer and use it in GitHub Desktop.
buzz_me(): receive notifications on your mobile from R!
## Inspired by http://bconnelly.net/2015/06/connecting-r-to-everything-with-ifttt/
## NB: set up IFTTT Maker channel to watch for R_event and then notify.
## Get your own personal maker key from https://ifttt.com/maker
## Put the code snippet below in ~/.Rprofile
buzz_me <- function(msg = "DONE!", event = "R_event") {
maker_key <- "yOuR_maKER_keY_GoES_HerE"
url <- paste0("https://maker.ifttt.com/trigger/", event, "/with/key/", maker_key)
if (requireNamespace("httr", quietly = TRUE)) {
invisible(httr::POST(url, body = list(value1 = msg), encode = "json"))
} else {
warning("you need to install 'httr' to use this function")
}
}
@dalejbarr
Copy link
Author

Here's an example of possible usage with magrittr pipes. The idea is that the function parse_output() takes the result of slow_modeling_function() as an argument and describes it with a single character string, which is passed along to buzz_me(). (You'll have to write your own slow_modeling_function() and parse_output() functions, of course.)

The %T>% pipe makes it so mod receives the result of the fitting function, since the parse_output(.) %>% buzz_me() sequence is used only for its side effect.

mod <- my_data %>% slow_modeling_function() %T>% {
    parse_output(.) %>% buzz_me()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment