cache.clean: Cleans selected files from the current cache directory

View source: R/cache.clean.R

cache.cleanR Documentation

Cleans selected files from the current cache directory

Description

Functions in the package include options to write files to a cache directory, set up with the cache.setup() function. Obsoletely files might be created if the name parameter in a function call is changed or if a function call is no longer being used. The cache.clean() function provides a way to find files that have not be modified in the last older_than days and lists the files for the user to agree to delete or not.

Usage

cache.clean(older_than = NULL, interactive = TRUE)

Arguments

older_than

A positive number indicating number of days (fractions allowed). Files with older modification times than this will be deleted after confirmation if interactive = TRUE.

interactive

Logical. TRUE indicates that confirmation will be required before files are deleted. FALSE indicates that files will be deleted without requiring confirmation. It is recommended to use TRUE except for carefully checked automated processes. Defaults to TRUE.

Details

The function is interactive if run in an interactive session with interctive = TRUE. In addition to deleting old files, the function will also optionally delete empty directories and, if the top level cache directory is also empty, then it will also optionally delete the cache directory and unset it. The latter will only be done in interactive sessions with interactive = TRUE to avoid breaking non-interactive code.

One way to clean only unused files is to run all current code and then run cache.clean() with older_than set to something greater than the number of days it takes for the code to run and less than when the code was previously run. For example, if your code takes 5 minutes to run and you previously ran it 2 days ago, you could run all your code and, when it has finished, use cache.clean(older_than = 1).

Value

NULL (invisibly). Primarily called to clean up the cache directory.

See Also

cache.setup()

Examples


  # Setup a cache directory
  cache.setup()
  # Now code with check = TRUE or save_out = TRUE will work, e.g.,
  # Create CFA keys
  keys0 <- c("grit_c", "grit_p", "hope_a", "hope_p")
  keys <- sapply(
    keys0, function(x) names(BFIGritHope)[grep(x, names(BFIGritHope))]
  )
  # Run models
  cfa_fit <- cfa.from.keys(
    keys, BFIGritHope, fit_save = TRUE, check = TRUE, save_out = TRUE
  )
  # Check that they are not estimated again.
  cfa_fit <- cfa.from.keys(
    keys, BFIGritHope, fit_save = TRUE, check = TRUE, save_out = TRUE
  )
  cache.clean(60/86400)  # Delete files not modified in the last minute.


semFromKeys documentation built on July 24, 2026, 5:07 p.m.