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.
Value
A character vector with class explorecourses_cache_list
containing:
File names without the .xml extension
Additional attributes:
total
: Number of files foundpath
: Full path to cache directoryyear
: Academic year filter (if provided)
Returns empty character vector (character(0)
) if no files found.
Details
The function supports two listing modes:
Year-specific: When
year
is providedLists: All files matching
"*_{year}.xml"
Validates year format before searching
Complete listing: When no
year
providedLists: All
"*.xml"
files in cache directory
File names in the returned vector:
Have the
.xml
extension removedRetain 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
cache_exists()
for checking specific cache filesclear_cache()
for removing cached filesread_xml_cache()
for reading cached data
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
}
} # }