Push notifications in R!

Despite its great litany of flaws, I love R. I love it super-hard. One of the best things about it is that people are always making weird packages that solve your problems; one of the annoying things is that you tend to find them just after they’d have been really useful, and that maybe they solve only a part of the problem. But it’s the beauty of open-source software: people make solutions to particular problems they have, and then they put in the work to make that available to the rest of us.

Anyway, one of my gripes over the course of my studies has been that you can’t really run anything in the background in R while you continue to work on another section of code: a lot of the statistical models I’ve been running use MCMCglmm, which is an amazing package but can be pretty time-intensive. Furthermore, my computer at work wasn’t really up to much, so quite often I couldn’t even work on any writing while my analysis was running. In all honesty, I should have looked harder at the options for running R in the cloud (e.g. on Amazon or Domino), but what I really wanted was just something that would give me a little notification when the analysis was done: that way, I could go off and work on something else until the results were ready for me to look at. As it was, there was a lot of clicking back and forth between windows and getting massively frustrated (or going away for half an hour, only to come back and find that I’d specified something incorrectly and it had failed within 10 seconds and needed to be restarted!).

Enter Brian Connelly‘s new package, PushoverR!

PushoverR takes advantage of the Pushover API, a service that receives messages from an application and sends them out to specified devices. Connelly has created this package so that Pushover receives a message from R, and communicates this to your iPhone or Android device. It’s really easy to set up, so here’s how to get started:

First, you need to sign up for a Pushover account. Head on over to Pushover, and register your email address. You’ll then get your user key (important information number 1!). After confirmation, you need to register your application – in this case, R! Here’s how I set up mine:


Once this is done, you’ll get an application token (important information number 2!). Now, you need to install ‘Pushover’ on your client device – this costs about £3, and is available from the App Store or Google Play:

photo 2

Now, we’re ready to go! Fire up your favourite R development environment (which should be RStudio, unless you’re a MORON), and get the relevant library installed and called up:

############## Libraries ############

Now, it’s a good idea to set up variables to hold your user ID and application token so that you don’t have to keep pasting them for any message you want to send. To protect myself from anyone here sending me messages to my phone, I’ve replaced the actual tokens with some nonsense:

############## My settings ###########
userID <- "u5schwarzenegger"
appToken <- "a1dontdisturbmyfriendhesdeadtired"

Anyway, we’re now ready to run some analysis – given that my time-consuming code tends to run via MCMCglmm, I’m just going to copy one of the examples given in Jarrod Hadfield’s excellent documentation. Then I’m going to send a simple message to myself that tells me when the analysis is complete; you could, of course, send some of the results in the message, but for now let’s stick to a very basic notification:

############ Run something ##########
prior.m3a.4 = list(R = list(V = diag(1), nu = 0.002), 
                   G = list(G1 = list(V = diag(3) * 0.02, 
                                      nu = 4), 
                            G2 = list(V = 1, nu = 0.002)))
m3a.4 <- MCMCglmm(tarsus ~ sex, 
                  random = ~us(sex):dam + 
                  data = BTdata, 
                  verbose = FALSE, 
                  prior = prior.m3a.4)
msg <- "Analysis complete"
## Send message
pushover(message = msg, 
         user = userID, 
         token = appToken)

We can set this to execute, and – while it runs – go and do something better, like watch youtube vidoes of Arnie violencing up some guys and then zinging their corpses. BLAM

Anyway. What do you know – my phone popped up with a little message!

photo 1


This is the very basic functionality of PushoverR – check out Brian’s ‘Readme‘ file for some more details of little extra bits. All of the info here was basically taken from that document, but I’ve added some pictures to make it more fun.

Let’s have another Arnie video as well.


3 thoughts on “Push notifications in R!”

  1. Ha! That’s pretty cool! Didn’t know about it, thanks! But for those that can’t bother with the setup, or who don’t have a smart phone (or are cheap like me and don’t want to pay for the app…), the “mail” package does a pretty good job:

    > # setup
    > install.packages(“mail”)
    > require(“mail”)
    > # your code here

    > # then you add this line to your code
    > sendmail(“your@email.com”, subject=”you can haz R!”, message=”your script has finished running! come check out your cool results! (or your cool errors!)”)

    and you’ll get an email when it’s done. the one limitation is you can only do 20 a day, I think!

    1. Good to know! PushoverR’s probably more useful for those of us who can take a quick break to walk around a picturesque Scottish campus 😉 The 20-a-day mail limitation is probably a good one – my immediate thought was to go and set up a loop to send you really annoying emails all day… I’m not sure whether there’s a character limit on pushoverr as well, I guess I’d be more likely to use it for notifications and perhaps the mail package to actually send a results summary to myself. Thanks for the comment!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s