Toying with Google Apps Script

[This article was first published on Apply R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Google offers an access to its services with Apps Scripts (JavaScript). That gives you a possibility to connect your spreadsheet to a fascinating variety of tools like geocoder, stock info, language translator, or email.

My java-scripting abilities are rather limited but just playing with tutorial examples I was quickly able to produce a script analyzing time distribution of received emails. It looks through your Gmail for the given contact and record the times of emails sent by it.

So this is email behaviour of my wife. You can see a peak at the noon when babies are having a nap and another local maximum at the end of the day when they are finally sleeping in beds.

The second example is my friend, very, very bad email responder (chance for a reply is ~50%). As you can read from the graph most essential emails are answered when the day start, then a few after a lunch… and finally evening responses (usually short and strict).



To try the script yourselves, open a new spreadsheet in GoogleDocs, select Tools -> Script Editor and copy the code below.


Run it, return to the spreadsheet and enter an email address of the contact of interest. The process takes a minute of two, be patient. You may want to add a command MailApp.sendEmail(“[email protected]”, “Finished“, “Google Apps Script”); before the last “}”  to be warned by mail when the job is finished.

After this, the first column is filled with time stamps information and we need a way to visualize it. Google App Script have a charting module but I found more convenient to use R/ggplot2 plotting services. A few lines of code are given below (before that the Google spreadsheet was published to web and the link was copied into, alternatively you could use RGoogleDocs).


Gmail blog: Gmail Snooze with Apps Script

To leave a comment for the author, please follow the link and comment on their blog: Apply R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)