R/clear.cache.R

Defines functions clear.cache

Documented in clear.cache

#' Clear MatchingPursuit Cache
#'
#' Deletes all files in the MatchingPursuit cache directory.
#'
#' @return Logical scalar. TRUE if all files were successfully removed, FALSE otherwise.
#' The return value is invisible.
#'
#' @export
#'
#' @examples
#' if (interactive()) {
#'   clear.cache()
#' }
clear.cache <- function() {

  cache.dir <- tools::R_user_dir("MatchingPursuit", "cache")

  if (!dir.exists(cache.dir)) {
    message("Cache directory does not exist: '", cache.dir, "'.")
    return(invisible(FALSE))
  }

  files <- list.files(cache.dir, full.names = TRUE, recursive = TRUE)

  if (length(files) == 0) {
    message("No files to remove in: '", cache.dir, "'.")
    return(invisible(TRUE))
  }

  ok <- file.remove(files)

  message("Removed ", sum(ok), " file(s) from cache.")
  if (any(!ok)) {
    warning("Some files could not be removed.")
  }

  return(invisible(all(ok)))
}

Try the MatchingPursuit package in your browser

Any scripts or data that you put into this service are public.

MatchingPursuit documentation built on April 9, 2026, 9:08 a.m.