Notifications from R

You just sent a long R job running. How to know when it’s done? Have it notify you by beeping, sending you a text, or sending you a notification via pushbullet.


You can use Rasmus Bååth’s beepr package to have your computer play a sound.

Install it from CRAN with


Then, at the bottom of your script, load the package and have it beep.


beepr comes with a bunch of different sounds (e.g., try beep("facebook")), or use a path to any wav file. I tried these cat sounds, but they came out (with my computer’s speaker) sounding more like a really unhappy electronic lion…not very pleasant.

beepr is cool, but most of my long-running jobs are on a distant server. It could be useful for local jobs on my Mac, but most of the time my computer is muted or the sound goes to my headphones (and my headphones are not always on my head). So I’m instead having my scripts send me a text or a notification via pushbullet.


There are a number of different packages for sending email from R (e.g., sendmailR and mailR). I tried Tyler Rinker’s gmailR package.

You can send yourself an email using the gmail() function. And since most cell phone companies have a method for sending a text via email, you can use this same function to send yourself a text. gmailR includes a function cell2email() that will help you figure out the appropriate email address to use, to send a text to your phone.

The only problem with gmailR is that you have to pass your gmail account and password to the gmail() function, and you don’t really want to have that stuff sitting in your R script.

So I wrote a little package mygmailR, that will instead pull your private information from a file (~/.gmail_private). I set up a separate gmail account for this purpose, and I set the security settings to use app-specific passwords.

My ~/.gmail_private file looks like the following: app-specific gmail password, gmail account to be the default “from” email address (perhaps special for this purpose), the email address to use to send a text, and the default “to” email (which is my usual gmail account).

password my_private_app_specific_password

You need to install a few packages. gmailR and mygmailR are not available on CRAN, so you need to install devtools and use the install_github() function to install them from GitHub.

install.packages(c("devtools", "rJython", "rJava", "rjson"))

In your script, to send yourself a text, you’d write

send_text("subject here" "body of message here")

To send yourself an email, write

send_gmail("subject here", "body of message here")


Another alternative (suggested to me by Peter Hickey and Jared Knowles) is to use Dirk Eddelbuettel’s RPushbullet package to send yourself a notification via pushbullet.

The main advantage of this, in my mind, is that there’s no gmail password sitting around on your system anywhere, but rather just your pushbullet “Access Token”, sitting in the file ~/.rpushbullet.json, so this is less of a security issue.

  1. Sign up for pushbullet; you’ll need a Google account.
  2. Install the pushbullet app on your phone or other device, or install the chrome extension.
  3. Go to your pushbullet account page to get your “Access Token”.
  4. Install the RPushbullet package from CRAN.
  5. install.packages("RPushbullet")
  6. Create a ~/.rpushbullet.json file with your api key and not much else.
  7. {
        "key": "your_api_key",
        "devices": [],
        "names": []
  8. Install jsonlite and use RPushbullet‘s pbGetDevices() function to get the identifiers for the devices you’ve registered with pushbullet.
  9. install.packages("jsonlite")
    fromJSON(pbGetDevices())$devices[,c("iden", "nickname")]
  10. Insert those device identifiers into your ~/.rpushbullet.json file.
  11. {
        "key": "your_api_key",
        "devices": [
        "names": [

Now you’re set! Use the pbPost() function to post a message to yourself.

pbPost("note", "Title of note", "Body of message")

By default, the message is posted to the first device listed in your ~/.rpushbullet.json file; to post it to a different device, use the argument deviceind, which takes a positive integer.

I’m still somewhat inclined towards using gmailR and mygmailR to send myself a text, but RPushbullet seems more secure.

Update: The word from Hadley: we should also check out gmailr. [But you can’t currently send email with gmailr.]

Tags: , ,

6 Responses to “Notifications from R”

  1. t3ngel Says:

    Hello There!

    What about notifyR?

  2. Error notifications from R | The stupidest thing... Says:

    […] Statistics, genetics, programming, academics « Notifications from R […]

  3. Jim Hester (@the_belal) Says:

    Hey Karl, since this post I have added the ability to send emails using my gmailr package (unfortunate name clash with Tyler Rinker’s package).

    There are a couple of benefits to using the new Gmail API rather than SMTP (as Tyler’s package does). First you don’t have to store your gmail login credentials anywhere (just a json with the app credentials). Second you can insert an email directly into your mailbox with whatever labels you prefer without sending it from anywhere.

    I think the RPushbullet and notifyR are both good suggestions as well and probably the best solution for this specific use case, just wanted to comment on the updated status of gmailr

  4. BMTX Says:

    Error in if (curl == “”) stop(paste(“No curl binary registered. “, “Install curl, and restart R and reload package”), :
    argument is of length zero

Comments are closed.