Fetch and process courses for multiple departments in parallel
Source:R/fetch.R
fetch_all_courses.Rd
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.
Arguments
- departments
Character vector. Department codes to fetch (e.g.,
c("CS", "MATH")
). IfNULL
, fetches from all available departments.- year
Character string. Optional academic year in
YYYYYYYY
format (e.g.,"20232024"
). IfNULL
, 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 identifieryear
: Academic yearsubject
: Department codecode
: Course numbertitle
: Course titledescription
: Course descriptionunits_min
: Minimum unitsunits_max
: Maximum unitsdepartment
: Department code of the courseterm
: Academic term (e.g., "Autumn", "Winter")term_id
: Numeric term identifiersection_number
: Section identifiercomponent
: Course component type (e.g., "LEC", "DIS", "LAB")class_id
: Unique identifier for the sectioncurrent_class_size
: Current enrollmentmax_class_size
: Maximum enrollment capacitySchedule information:
days
: Days of the week (e.g., "Mon, Wed, Fri")start_time
: Start time of the classend_time
: End time of the classlocation
: Class location/room
Instructor information:
instructors
: Combined instructor information with rolesinstructor_names
: Names of instructorsinstructor_sunets
: SUNet IDs of instructorsinstructor_roles
: Roles of instructors
Returns NULL
if no courses found for any department.
Details
The function follows this process:
Input preparation:
Validates year format if provided
Fetches all departments if none specified
Cleans department list (removes duplicates and invalid codes)
Parallel processing:
Uses
furrr
for parallel executionShows progress updates via
progressr
Safely handles errors per department
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
fetch_department_courses()
for single department fetchingfetch_departments()
for getting department codesvalidate_academic_year()
for year format details
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)
} # }