Skip to contents

Retrieves courses from multiple departments concurrently using parallel processing. If no departments are specified, fetches courses from all available departments. Provides progress updates during processing and handles errors gracefully.

Usage

fetch_all_courses(departments = NULL, year = NULL, cache_dir = NULL)

Arguments

departments

Character vector. Department codes to fetch (e.g., c("CS", "MATH")). If NULL, fetches from all available departments.

year

Character string. Optional academic year in YYYYYYYY format (e.g., "20232024"). If NULL, fetches data for the current academic year.

cache_dir

Character string. Optional path to cache directory. If provided, enables caching for all department fetches.

Value

A tibble (data frame) containing course information with columns:

  • objectID: Unique course identifier

  • year: Academic year

  • subject: Department code

  • code: Course number

  • title: Course title

  • description: Course description

  • units_min: Minimum units

  • units_max: Maximum units

  • department: Department code of the course

  • term: Academic term (e.g., "Autumn", "Winter")

  • term_id: Numeric term identifier

  • section_number: Section identifier

  • component: Course component type (e.g., "LEC", "DIS", "LAB")

  • class_id: Unique identifier for the section

  • current_class_size: Current enrollment

  • max_class_size: Maximum enrollment capacity

  • Schedule information:

    • days: Days of the week (e.g., "Mon, Wed, Fri")

    • start_time: Start time of the class

    • end_time: End time of the class

    • location: Class location/room

  • Instructor information:

    • instructors: Combined instructor information with roles

    • instructor_names: Names of instructors

    • instructor_sunets: SUNet IDs of instructors

    • instructor_roles: Roles of instructors

Returns NULL if no courses found for any department.

Details

The function follows this process:

  1. Input preparation:

    • Validates year format if provided

    • Fetches all departments if none specified

    • Cleans department list (removes duplicates and invalid codes)

  2. Parallel processing:

    • Uses furrr for parallel execution

    • Shows progress updates via progressr

    • Safely handles errors per department

  3. Results handling:

    • Reports any department-specific errors

    • Combines successful results

    • Returns NULL if no valid results

Progress updates show:

  • Current department being processed

  • Extraction of results

  • Final merging step

Error handling

This function will trigger errors for:

  • Department-specific processing errors

  • No courses found across all departments

  • Year validation issues

See also

Examples

if (FALSE) { # \dontrun{
# Fetch all departments
all_courses <- fetch_all_courses()

# Fetch specific departments
stem_courses <- fetch_all_courses(
  departments = c("CS", "MATH", "PHYSICS")
)

# Fetch with year and caching
courses_2023 <- fetch_all_courses(
  year = "20232024",
  cache_dir = "course_cache"
)

# Process results with dplyr
library(dplyr)

# Count courses per department
dept_summary <- all_courses %>%
  group_by(department) %>%
  summarise(
    n_courses = n_distinct(objectID),
    n_sections = n()
  )

# Find large classes
large_classes <- all_courses %>%
  filter(current_class_size >= 100) %>%
  select(department, code, title, current_class_size)
} # }