Ever wished you could grab a guilt-free coffee whilst your humungous R script completes processing and be notified when it’s done? With the glorious pushoverr package by Brian D Connely, you can!

Here’s the final effect we’re looking for:

This post will look at a simple example of how to set up Pushover on an Android phone, install the pushoverr R package and send yourself a push notification after running a script.

Installing the Pushover app

I’m an Android user so I’m grabbing the Android app. Download from the Google Play Store or iTunes Store if you’re on iOS. There are even desktop clients if you get hooked (like me).

There’s a $4.99 one-off cost for the app (view pricing info), but you should be able to sign up for a free 7-day trial.

Once you’ve installed the app on your phone, you need to create a new app in your Pushover account in order to make API calls. Navigate to Pushover.net, log in and go to “Apps and plugins” in the top nav (or just go straight to the build page if you like).

Fill out the form fields along the following lines - you can describe your app however you like really.

Screenshot of Pushover app creation form fields

Screenshot of Pushover app creation form fields

When your notifications come through, the default is for them to have a Pushover icon. I choose to add a little custom RStudio icon just for fun (created in powerpoint & saved as image). Not a designer This icon will show up in the notification pane of your phone - if you end up using Pushover in multiple applications (it has a connector with IFTTT, for example) then it’s nice that the notification icon distinguishes between your notification’s source.

Store your user key and application key

The pushoverr package makes use of the Pushover API, for which we’ll need a user key and API key.

Once you’ve created your Pushover application, you should see a confirmation screen which includes your API token / key. Make a note of this token:

my_api_key <- "long_crazy_secure_value"

Secondly, navigate back to Pushover.net and you should see a user key in the top right corner. Make a note of this, too:

my_user_key <- "another_long_value"

Testing out Pushover (optional)

You might also like to test that notifications are successfully sending to your phone. You can do this from Pushover.net. The image on the left below shows the form you can fill out, and on the right is the resulting notification on your phone.

testing pushover notifications

testing pushover notifications

Connecting R with Pushover

Alright! Nearly there. Now you just need to install the pushoverr package.

# Install with either
install.packages("pushoverr")

# Or, if you want the latest dev version
devtools::install_github("briandconnelly/pushoverr")

Once installed, provided you have set your user key and app key (above), you should be able to send yourself a test message from R:

library(pushoverr)
pushover("Hello from R!", 
         user = my_user_key,
         app = my_api_key)

Your phone should give you a new push notification:

Not a designer

Putting it all together

That’s it! You can now add a call to pushover() at the end of any long-running or automated / overnight scripts, and be notified on completion. For example:

library(tidyverse)
library(googleAnalyticsR)

# We have 6 GA views and want some simple user data for them all
my_site_views <- c(11223344,88776655,00997788,11884466,77336644,99880033)

# Function to return users by date for the provided view ID
combine_ga_data <- function(view_id) {
  site_data <- google_analytics_4(viewId = view_id,
                                                    date_range = c(Sys.Date()-30,Sys.Date()-1),
                                                    metrics = "users",
                                                    dimensions = "date") %>% 
    mutate(view_id = view_id)
}

# Iterate over all view IDs
many_site_results <- map_df(my_site_views,
                                   combine_ga_data)

# Get some summary stats
total_users <- sum(many_site_results$users)
min_users <- many_site_results %>% 
  filter(users == min(users))

# Send our push notification
pushover(message = paste0("Your amazing Google Analytics Results have finished. There were: ",
               total_users, 
               " users across all sites and the lowest user count was ", 
               min_users$users),
         title = "GA Results complete",
         user = my_user_key,
         app = my_api_key)

Not a designer

Many thanks to briandconnelly for creating this very useful package.