Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Forms Data Extraction #29

Merged
merged 12 commits into from
Dec 4, 2023
Merged

Google Forms Data Extraction #29

merged 12 commits into from
Dec 4, 2023

Conversation

cansavvy
Copy link
Collaborator

@cansavvy cansavvy commented Nov 29, 2023

Purpose/implementation Section

What changes are being implemented in this Pull Request?

This is a set of functions that retrieve and get data from google forms.

Usage

Here's how these work. You can pass in a single URL or form id to a form and retrieve info:

authorize("google")
form_info <- get_google_form("https://docs.google.com/forms/d/1Z-lMMdUyubUqIvaSXeDu1tlB7_QpNTzOk3kfzjP2Uuo/edit")

### OR You can give it a direct form id
form_info <- get_google_form("1Z-lMMdUyubUqIvaSXeDu1tlB7_QpNTzOk3kfzjP2Uuo")

You can extract multiple forms using get_multiple_forms() function

authorize("google")
form_list <- googledrive::drive_find(shared_drive = googledrive::as_id("0AJb5Zemj0AAkUk9PVA"), type = "form")
 multiple_forms <- get_multiple_forms(form_ids = form_list$id)

Base automatically changed from cansavvy/testing to main November 29, 2023 20:22
@cansavvy cansavvy marked this pull request as ready for review December 1, 2023 14:46
}


google_pagination <- function(first_page_result) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is needed for google forms that have a lot of responses, however I don't have any google forms that have that many responses so I can't test this. But I'll keep this infrastructure here for when we do have some data that needs it.

@@ -1,55 +0,0 @@
# Extracting data from Google drive files
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted all this because now we are just passing tokens to googledrive and having that do the work for us! Thanks to Howard for helping me figure this out.

@@ -68,7 +68,8 @@ get_token <- function(app_name, try = FALSE) {
get_stored_token <- function(app_name) {
if (app_name == "calendly") token <- getOption("calendly")
if (app_name == "github") token <- getOption("github")
if (app_name == "google") token <- try(readRDS(file.path(cache_secrets_folder(), "google.RDS")), silent = TRUE)
if (app_name == "google") token <- getOption("google")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized we don't need to readRDS we can just set this as an option too.

@cansavvy cansavvy mentioned this pull request Dec 1, 2023
Copy link
Contributor

@howardbaik howardbaik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_google_form() may need to be examined as form_info$title contains NULL.

get_multiple_forms() looks good to me.

@@ -71,6 +71,7 @@ authorize <- function(app_name = NULL,
scope = scopes_list,
...
)
googledrive::drive_auth(token = token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why you had to add this line. Does this affect the Google Analytics code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At times we borrow the googledrive and googlesheets packages to do work for us. This makes it so that users don't have to do authorization for every single package. Instead they authorize metricminer and we send that authorization to the dependency packages we need.

} else {
answers_df <- "no responses yet"
}
return(list(title = result$form_metadata$result$info$title,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I run form_info <- get_google_form("https://docs.google.com/forms/d/1Z-lMMdUyubUqIvaSXeDu1tlB7_QpNTzOk3kfzjP2Uuo/edit"), I get NULL as the value for form_info$title.

Is this expected behavior?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After running the code to grab multiple forms, I see that code returns the title of the Google form, making me think the above behavior may be a bug.

Comment on lines +108 to +109
metadata = metadata,
answers = answers_df))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of making these tibbles? The output can get pretty ugly: #25

@cansavvy
Copy link
Collaborator Author

cansavvy commented Dec 4, 2023

get_google_form() may need to be examined as form_info$title contains NULL.

get_multiple_forms() looks good to me.

This is a more universal problem that I want to address for all these functions #32

I'm thinking the solution should be 1) Make a specialized data class type to handle these data as well as a 2) set of handler functions. But this will be a much bigger set of work than will be done in this PR.

@cansavvy
Copy link
Collaborator Author

cansavvy commented Dec 4, 2023

I agree that these are issues but I think they will take more to address than is the scope of this PR. For ease of addressing this I'm going to merge this and move on.

@cansavvy cansavvy merged commit 5745302 into main Dec 4, 2023
5 checks passed
@cansavvy cansavvy deleted the cansavvy/google-forms branch December 4, 2023 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants