googleformr at Work: Pneumatic Road Tube Allegory

Steve Simpson (@data_steve) created the googleformr package to enable users to easily send information to a Google Form.  It’s a nice way to send and securely store data via R and the price is great…FREE!

A Pneumatic Road Tube Allegory…Kinda

My team has been working on a data validation task at work and we’ve built a couple of  internal packages & scripts to help us with the task.  We’ve set it up so non-technical colleagues can use the packages and scripts as automated .bat/.sh files.

After a few months we wanted to make improvements but had no evidence of what packages and scripts were used most often, what parts were worth the additional development time.  What we needed was something like those strips used on streets to determine traffic flow and usage.  Turns out those strips are called pneumatic road tubes in case you ever get that as a Jeopardy question.  They provide a safe, low cost, and simple way to collect information.  Exactly what we needed just a code based version…

atctop

But, like most CRAN mirrors, we have had no way of even knowing when a package is downloaded let alone who’s using the package & scripts and how often.  But once googleformr was released that changed.

Our initial phase was just to see who was using the packages/scripts and when.  All that was required to answer this question was (A) making a Google Form with a single text box and then (B) adding a couple of lines of code from googleformr to send a unique identifier to a google form (which can be set up to go to a Google Spreadsheet).  A little help from Jenny Bryan’s googlesheets package with some Hadley ggplot2 love and we had the following image showing employee usage of a particular script for the first several weeks.

I bet you’re asking, “How’d we do it?” Well…  See the explanation and mock code below to make your own code based pneumatic road tube.

usage

Step 1: Get googleformr

Getting googleformr is simple.  This simple chunk should have you up and running with googleformr in a jiffy (do people still say jiffy?):

if (!require("pacman")) install.packages("pacman")
pacman::p_load_gh("data-steve/googleformr")

Step 2: Make a Google Form

Then make a Google Form with a text entry.  Here’s an image showing the steps to link the form to a spreadsheet. In the Google Form edit: 1) Click Responses Tab 2) Click those three dot thing-ies 3) Click “Select response destination” 4) click “Create a new spreadsheet”  Step 1 done.  Almost there…

set_up_spreadsheet

In this image we see the Google Form and the accompanying Google Sheet.

gform

Step 3: Send Information Via googleformr

Just use the gformr function, add the Google Form url (from Step 1) and viola you have  a function that allows you to send information to a Google Form (in this case I made a ping function).  This is the function we can use to send information about the package and script usage within our company.

ping <- googleformr::gformr('https://docs.google.com/forms/d/1sLh9CBW7RuzShqnbt260Ud85I_I2qQEdw_S6iMytJx4/prefill')
ping('employee1234')

You’re in business with a secure way to send data from R to Google Spreadsheet.

Go ahead try it.  Replace ’employee1234′ with whatever you want, go to the Google Sheet, and watch the R code you send auto-magically be sent to the spreadsheet. I’ve made this sheet public for demonstration purposes, but generally it’s recommended that you keep the sheets private.

With this simple code snippet placed in the internal scripts and packages we were able to determine what packages and scripts were used, by whom, and how frequently.  So far our pneumatic road tube code  has provided insight into what tools to improve and new features to consider.  And it only took 5 minutes to set up end to end.

Conclusion

We’re just getting started with the information we collect to make our internal R tools better.  I think that googleformr is an interesting package with a ton of potential for securely sending information for free.  I’d love to hear about your ideas on how to use it via the comments below.

About tylerrinker

Data Scientist, open-source developer , #rstats enthusiast, #dataviz geek, and #nlp buff
This entry was posted in analysis, r, work flow and tagged , , , , , , . Bookmark the permalink.

8 Responses to googleformr at Work: Pneumatic Road Tube Allegory

  1. Great post! I’ll have to try that out

    I don’t understand how this helps you know what packages people at work use, and why the need for google forms in this use case

    • tylerrinker says:

      Thanks for the question. It doesn’t help us know which packages people use at work. It helps us know which of our internal packages people use at work. The snippet I pasted above is minimal. But it basically will securely send the message to the sheet that “hey this script or package was used by X at Y time”. You can put the snippet in as many times and places as you want and as creatively as you can think (we collect unique identifier but that’s minimal). You can send what ever information R can collect (there are ethical considerations here; i.e., the question isn’t “can I collect this” but “should I collect this”). So to answer your first question it only helps us know usage of what internal packages (and/or scripts) that we created. The answer to the second question is that google forms is a API endpoint that allows you to send information without the fear of someone going to the spreadsheet and mucking about. There are other ways to collect this information but this was the one standardized, easy way we arrived at.

  2. Pingback: googleformr at Work: Pneumatic Road Tube Allegory – Mubashir Qasim

  3. Just for others who might wonder. To send more variables, add more questions to your form and use:

    ping <- googleformr::gformr('https://docs.google.com/forms/d/1vpj_p3oaxG7mX1OFxpgOdQOy7S2b9qyyPdpn98VioDM/prefill&#039😉
    ping(c('hello','world'))

  4. Adi says:

    Hi, that’s really nice!, but I don’t get something:
    If you already know and use the googlesheets package, why not use it “all the way”? i.e., the function gs_add_row(…) does the trick, and you don’t need any forms for that… as it is, your form is completely for internal purposes and you don’t need it for user data intake.

    • tylerrinker says:

      I believe it would mean you need an API key or permissioning would need to be granted. I may be mistaken but is there a way to track usage without exposing your own credentials via googlesheets? The googleformr route definitely allows for an open API connection that does not require giving out any credentials. If indeed I need to share credentials with co-workers to use google sheets I’d say that seems like a pretty big risk that I’m unwilling to take.

      • Adi says:

        Now I see what you mean and that’s a good point.
        Indeed, in order to write directly to a google sheet you would have to “share to anyone with link” to read/write (thus the collected information is visible to the world), or conversely do an OAuth2.0 authentication/API key as you wrote…

Leave a comment