The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

Working with groups

Introduction

This vignette demonstrates how to retrieve group memberships in a course using the Canvas LMS API.

Step 1: List courses

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

Step 2: Retrieve all groups in the course

# Retrieve all groups in the selected course
groups <- get_course_groups(canvas, course_id)

# Extract the group IDs
group_ids <- groups$id

Step 3: Retrieve group memberships


# 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)
})

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.