Skip to contents

Lists all cached XML files in the cache directory, optionally filtered by academic year. Returns a character vector of filenames without extensions, with additional metadata attached as attributes.

Usage

list_cache(year = NULL, cache_dir = NULL)

Arguments

year

Character string. Optional academic year in YYYYYYYY format (e.g., "20232024") to list only cache files from a specific year.

cache_dir

Character string. Optional path to the cache directory. If NULL, uses the default cache location.

Value

A character vector with class explorecourses_cache_list containing:

  • File names without the .xml extension

  • Additional attributes:

    • total: Number of files found

    • path: Full path to cache directory

    • year: Academic year filter (if provided)

Returns empty character vector (character(0)) if no files found.

Details

The function supports two listing modes:

  1. Year-specific: When year is provided

    • Lists: All files matching "*_{year}.xml"

    • Validates year format before searching

  2. Complete listing: When no year provided

    • Lists: All "*.xml" files in cache directory

File names in the returned vector:

  • Have the .xml extension removed

  • Retain any year suffixes (e.g., "CS_20232024")

  • Are returned in the order found by the filesystem

Error Handling

If the cache directory cannot be accessed or listed. The error will include the specific error message and cache directory path.

See also

Examples

if (FALSE) { # \dontrun{
# List all cached files
files <- list_cache()
print(files)  # Uses special print method for explorecourses_cache_list

# Get total number of cached files
total <- attr(files, "total")

# List files for specific year
files_2023 <- list_cache(year = "20232024")

# List files in custom cache directory
files <- list_cache(cache_dir = "~/my_course_cache")

# Check if any files were found
if (length(files) > 0) {
  # Process files
}
} # }