Last active
December 14, 2016 18:41
Function to obtain course gradebook from Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rcanvas) | |
library(tidyverse) | |
get_course_gradebook <- function(course_id) { | |
course_assignment_ids <- get_course_items(course_id, "assignments") %>% .$id %>% as.list() | |
course_ids <- rep(course_id, length(course_assignment_ids)) %>% as.list() | |
get_assignment_submissions <- function(course_id, assignment_id) { | |
url <- sprintf("%s/api/v1/courses/%s/assignments/%s/submissions", canvas_url(), course_id, assignment_id) | |
httr::GET(url, query = list(access_token = Sys.getenv("CANVAS_API_TOKEN"))) %>% | |
httr::content("text") %>% | |
jsonlite::fromJSON(flatten = TRUE) | |
} | |
assignments <- purrr::map2_df(course_ids, course_assignment_ids, get_assignment_submissions) | |
students <- get_course_items(course_id, "enrollments") %>% dplyr::select(user.name, user_id, grades.final_score, course_id) | |
dplyr::left_join(assignments, students, by = "user_id") | |
} | |
gradebook <- get_course_gradebook(course_id = 20) #Where course_id is a valid Canvas course id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment