Learn R Programming

rgoogleclassroom

rgoogleclassroom is a Google API wrapper that allows you to use Google Classroom and Google Forms from the coziness and comfort of R.

You can read the rgoogleclassroom package documentation here.

To use this package you need to have a Google Classroom account. Go here to get that: https://edu.google.com/workspace-for-education/classroom/

How to install

If you want the development version (not advised) you can install using the remotes package to install from GitHub.

if (!("remotes" %in% installed.packages())) {
  install.packages("remotes")
}
remotes::install_github("datatrail-jhu/rgoogleclassroom")

Usage

To start, you need to authorize() the package to access your files. Select all the scopes you feel comfortable sharing. Note that you need to select certain scopes for certain functions to work.

authorize()

Basics

There are different objects on the Google API:

  • courses
  • forms
  • courseWorks
  • courseWork Materials
  • topics

Most of these objects have functions that do the following:

  • get_<object>_list()
  • create_<object>()
  • get_<object>_properties()

For example:

get_course_list(owner_id) retrieves a list of courses for a particular owner id. create_course() creates a course get_course_properties(course_id) retrieves the properties of a course given its id.

These can be built together to be pretty nifty.

Example workflow

Run the function to authorize the app to use your Google account.

authorize()

Retrieve whatever your owner id for Google Classroom is.

owner_id <- get_owner_id()

Now you can retrieve a list of courses that are associated with your owner id.

course_df <- get_course_list(owner_id)

For the following examples, we will need to use

Create a course
new_course <- create_course(owner_id$id, name = "New course")

Managing materials

We can create new material for the students using by building this together like this:

# Create a course we will use for this test
owner_id <- get_owner_id()
new_course <- create_course(owner_id$id, name = "New course")

# Create material at this course
new_material <- create_material(course_id = new_course$id,
                                title = "New material")

# Retrieve the material info
materials_info <- get_materials_properties(course_id = new_course$id,
                                             materials_id = new_material$id)

Retrieve the list of all the materials for the course

materials_list <- get_materials_list(course_id = new_course$id)

Managing courseworks

We can manage courseworks!

# Create a new coursework
new_coursework <- create_coursework(course_id = new_course$id,
                                    title = "New coursework",
                                    due_date = lubridate::today() + lubridate::hours(24))

# Get coursework properties
course_work_info <- get_coursework_properties(course_id = new_course$id, coursework_id = new_coursework$id)

# Retrieve all the courseworks for this course
coursework_list <- get_coursework_list(course_id = new_course$id)

Make a quiz

We can build a quiz like this:

course_id <- get_course_list()$courses$id[1]

quiz_form_id <- create_quiz(
  course_id = course_id,
  quiz_title = "new quiz",
  quiz_description = "This is a great quiz",
  due_date = "2025-12-1")

We can create a new multiple choice question in the quiz we just made by using these steps:

create_multiple_choice_question(
  form_id = quiz_form_id$formId,
  question = "What answer do you want?",
  choice_vector = c("A", "B", "C", "D"),
  correct_answer = 3,
  shuffle_opt = TRUE
)

Delete or archive courses

# Clean up this test course
archive_course(new_course$id)
delete_course(new_course$id)

Copy Link

Version

Install

install.packages('rgoogleclassroom')

Monthly Downloads

156

Version

1.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Candace Savonen

Last Published

March 25th, 2025

Functions in rgoogleclassroom (1.0.0)

get_coursework_list

Get list of courseworks for a course
get_course_properties

Get Google Classroom Course Properties
get_endpoint

Generate endpoint for the Google classroom API
get_coursework_properties

Get Google Classroom Course Properties
get_drive_file_list

Get list of files from a Google Shared Drive
get_form_responses

Get form responses
get_linked_quizzes_list

Get list of forms used in a course as quizzes
create_multiple_choice_question

Create a multiple choice question
get_materials_list

Get list of materials for a course
delete_coursework

Delete a Google Classroom Coursework
delete_course

Delete a Google Classroom Course
parse_q_tag

Parse apart a tag
translate_questions_api

Translate Markua questions for submission to Google API
parse_quiz

Parse Quiz and Other Checking Functions
create_topic

Create a new topic
is.google_forms_request

Check if the object is a google forms request object
get_materials_properties

Get Google Classroom Materials properties
make_form_quiz

Turn a form into a quiz
date_handler

Handle and parse a due_date
create_text_question

Create a text question
get_topic_properties

Get Google Classroom Topic Properties
good_quiz_path

Path to good example quiz
create_form

Create a new form
get_form_properties

Get Google Form Properties
update_form_settings

Create a multiple choice question
markdown_quiz_path

Get file path to an example quiz
ottr_quiz_to_google

Create Google Form Quiz from Markua quiz
extract_meta

Extract meta fields from a tag
get_course_list

Get list of courses
get_topic_list

Get list of topics for a course
get_owner_id

Get ownerId based on credentials
publish_coursework

Publish a Google Classroom CourseWork
%>%

Pipe operator
parse_quiz_df

Parse quiz into a data.frame
time_handler

Handle and parse a time
check_quiz_attributes

Check Quiz Attributes
authorize

Authorize R package to access Google classroom API
auth_from_secret

Use secrets to Authorize R package to access Google classroom API
check_question

Check Quiz Question Set Up
archive_course

Archive a Google Classroom Course
check_quiz

Check Quiz
check_quiz_question_attributes

Check a question's attributes
check_quiz_dir

Check all quizzes' formatting for Leanpub
bad_quiz_path

Path to bad example quiz
check_all_questions

Check all quiz questions
create_quiz

Create a quiz at a course
check_quizzes

Check all quizzes in a directory
create_material

Create a new material
create_coursework

Create a new coursework
copy_form

Make a copy of an existing form
create_course

Create a new course
commit_to_form

Commit changes to a Google form