googleformr is an API to Google Forms, allowing users to POST data securely to Google Forms without needing authentication or permissioning.
5-min How-Tos: 2 use cases
There's many ways to use googleformr to collect data. In the first example below, the developer is essentially using googleformr to use herself data back from a user's implementation of her code. The second use case show cases how to set up a function in your package so that users can send comments directly to you, by-passing email or github issues.
Use Case #1: Track Package 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?). We're using dependencies=TRUE suboption to insure the
selectr dependencies is also installed, if not already:
devtools::install_github("data-steve/googleformr", dependencies = TRUE)
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:
- Click Responses Tab
- Click those three dot thing-ies
- Click “Select response destination”
- click “Create a new spreadsheet”
Step 1 done. Almost there… In this image we see the Google Form and the accompanying Google Sheet.
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 pingfunction). 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') 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 R scripts of our internal 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.
Use Case #2: Send User Feedback to googleformr
googleformr comes with a
comments_gformr function that was built with googleformr, allowing useRs to send comments to a Google Form I've created for collecting user feedback.
Not every user
- has a github account for posting issues,
- runs their own blog,
- haves access to nearby useR groups.
So finding new ways to stay accessible to my useRs is important to me.
Give it a try with something like below!
googleformr::comments_gformr( post_content = "It would useful for functionality to help distinguish in the data between lots of comments from one useR vs. many useRs" )
Create your own feedback function
First, make sure to grab googleformr from CRAN, if you haven't yet. I love pacman as my library / function handler. The
p_load will load a library. If it isn't installed, it will install from CRAN and then load it.
if (!require("pacman")) install.packages("pacman") pacman::p_load(googleformr)
You can create your own
feedback_pkg_name function by linking it to a Google Form. Get your forms started at the Google Forms page. Once you have a google form created with one short answer question, grab the form's url and use code below:
# create function form <- "your_google_form_url" feedback_pkg_name <- gformr(form , custom_reply = "Thanks for supporting pkg_name")
Note: it is recommended to call your feedback function
- something clearly signalling a feedback purpose
- but also something specific to your package.
So a function name following the pattern
feedback_pkg_name should get the best of easy IntelliSense auto-complete and distinguishability from other packages using the same functionality.
Once you re-document and re-build your package and post it to github or CRAN, your users can send feedback directly to you from the R console by simply putting their feedback into your feedback function.
fdbk <- # their comments feedback_pkg_name(fdbk)
You can test that your new
feedback_pkg_name function works by:
- sending a test message to your Google Form and see if it shows up and/or
- using the
check_form_worksfunction like so:
check_form_works( comments_pkg_name("test") ). Either "All good" will appear or a specific http status message describing the error.
You can also extract Google Form question text or entry points using to make sure you can bring back the same information as is on your form:
# questions form <- "your_google_form_url" form %>% get_form() %>% get_form_questions() # entry ids form %>% get_form() %>% get_form_entry_ids()
You are welcome to: