system.done = system.time + pbPost

I love Pushbullet and I love R, so when Dirk Eddelbuettel’s brilliant package RPushbullet showed up on CRAN, I was rather intrigued. Then Karl Broman followed up with RPushbullet for error notifications from R:

and I was obsessed. My housemate can attest to this; I talked about how R was alerting me to errors via pushes to my phone for days and I think she started to get annoyed (or maybe just resentful–SAS probably can’t use Pushbullet).

The error function is great, but wasn’t halting my scripts when there was an error. So I would run a script at work, head home, and minutes later my phone would be barraged with error message after error message as my script tried to move forward but failed for every new line of code. Which is honestly probably a pretty easy fix in the error function but I preferred tackling that issue in a different way.

I had been using a simple function I called done for a while that alerted me when something was, well, done.

This function also uses the beepr package which can make a whole hoard of sounds when run so I can annoy my coworkers when my scripts finish as well.

The combination of the error function and done is all fine and dandy, but I wanted a way to be alerted when I had an error or when the script was done, without a barrage of error messages being sent to my phone. It would also be nice to know how long my scripts took to finish. Was my computer chugging away for 15 minutes after I left? Or did it take 5 hours? I guess I could figure this out by taking a look at when my notification came through, but wouldn’t it be more fun to harness the power of system.time and pbPost to get an error message when one occurs or get a push notification when everything is done? This is nothing complicated. Adding just a few lines to system.time sends me a push when everything fails, alerting me to my R coding inadequacies, or if it works, alerting me to my ability to do something normal. For once.

So without further ado: system.done

The expr argument is the same as you would pass to system.time and the devargument is the device ID assigned in your ~/.rpushbullet.json file. I haven’t included something like:

in the functions above because my wonderfully mediocre package Imisc on github loads them automatically. You can view my mediocre package here and install it via:

Not that you would want to. Nothing is documented and most of the functions are either copied from other packages and stackoverflow posts or borrowed from John Fox and edited slightly. There are maybe 4 or 5 functions made of completely original content.

3 comments to this article

  1. Karl Broman

    on January 31, 2015 at 11:02 pm - Reply

    Sorry for causing the excess phone notifications! I didn’t learn until later that options("error") behaves differently depending on whether you’re in an interactive session or not. Solved the problem by adding if(!interactive()) stop(geterrmessage()).

  2. Karl Broman

    on January 31, 2015 at 11:06 pm - Reply

    Well, duh! I just realized that you were the one who’d pointed out (in a comment at my blog) that scripts weren’t stopping on error.

    • ikkyle

      on February 1, 2015 at 1:02 am - Reply

      Yes, that was indeed me. Adding the !interactive() bit is definitely an easier way to solve my problem. But hey, my approach might be in the very least, a good demonstration in how to take innovative ideas from others, change a couple lines of code, and come out with something mediocre that you can pretend is your own.

      Anyway, I promise that I have blog posts planned that are a little more creative and involve less code stealing. Who knows, maybe someday I’ll even post something of value.

Leave a Reply