Toying with Google Apps Script

January 11, 2012
By

(This article was first published on Apply R, and kindly contributed to R-bloggers)

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 his blog: Apply R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.