From d9c5a75bbcd2ae278be0ccd7b9c1ee06ed646887 Mon Sep 17 00:00:00 2001 From: Brooks Ambrose Date: Mon, 20 May 2024 13:33:51 -0700 Subject: [PATCH] add include to submissions.R Add include argument to get submissions, principally to allow comments on submissions to be downloaded. https://canvas.instructure.com/doc/api/submissions.html#method.submissions_api.index --- R/submissions.R | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/R/submissions.R b/R/submissions.R index faf03a4..010a511 100644 --- a/R/submissions.R +++ b/R/submissions.R @@ -2,6 +2,7 @@ #' @param course_id A valid canvas course id #' @param type Either "quizzes" or "assignments" #' @param type_id A valid quiz or assignment id +#' @param include A character vector. Options are submission_history, submission_comments, rubric_assessment, assignment, visibility, course, user, group, or read_status. #' @name submissions NULL @@ -16,11 +17,18 @@ NULL #' @examples #' \dontrun{get_submissions(27, "quizzes", 2915)} #' \dontrun{get_submissions(27, "assignments", 254)} -get_submissions <- function(course_id, type, type_id) { +get_submissions <- function(course_id, type, type_id, include=NULL) { if (!type %in% c("quizzes", "assignments")) stop("type must be 'quizzes' or 'assignments'") url <- make_canvas_url('courses', course_id, type, type_id, 'submissions') + if(!is.null(include)){ + iopt<-c("submission_history", "submission_comments", "rubric_assessment", "assignment", "visibility", "course", "user", "group", "read_status") + if(!all(include%in%iopt)) stop(sprintf("include must be any of: %s",paste0(iopt,collapse=", "))) + inc<-paste0("include[]=",include) + inc<-paste0(inc,collapse="&") + url<-paste(url,inc,sep="?") + } args <- list(access_token = check_token(), per_page = 100) process_response(url, args) %>% @@ -36,11 +44,18 @@ get_submissions <- function(course_id, type, type_id) { #' @md #' @examples #' \dontrun{get_submission_single(1350207, "assignments", 5681164, 4928217)} -get_submission_single <- function(course_id, type, type_id, user_id) { +get_submission_single <- function(course_id, type, type_id, user_id, include=NULL) { if (!type %in% c("quizzes", "assignments")) stop("type must be 'quizzes' or 'assignments'") url <- make_canvas_url('courses', course_id, type, type_id, 'submissions', user_id) + if(!is.null(include)){ + iopt<-c("submission_history", "submission_comments", "rubric_assessment", "assignment", "visibility", "course", "user", "group", "read_status") + if(!all(include%in%iopt)) stop(sprintf("include must be any of: %s",paste0(iopt,collapse=", "))) + inc<-paste0("include[]=",include) + inc<-paste0(inc,collapse="&") + url<-paste(url,inc,sep="?") + } args <- list(access_token = check_token(), per_page = 100) resp <- canvas_query(url, args, "GET")