This vignette demonstrates how to retrieve group memberships in a course using the Canvas LMS API.
library(vvcanvas)
# Specify the Canvas API authentication details
canvas <- list(
api_key = "YOUR_API_KEY",
base_url = "https://your_canvas_instance/"
)
# Retrieve all courses
courses <- get_courses(canvas)
# Select a course (replace the index with the desired course)
course_id <- course$id[1] ## the first course in courses
# Retrieve group memberships using purrr
memberships <- purrr::map_df(group_ids, ~{
group_id <- .x
# Retrieve the group's memberships
group_memberships <- get_group_users(canvas, group_id)
# Extract user names from memberships
user_names <- group_memberships$name
# Create a data frame with group memberships
group_df <- data.frame(group_id = rep(group_id, length(user_names)),
user_name = user_names,
stringsAsFactors = FALSE)
return(group_df)
})