Skip to contents

Deletes the saved results chosen by namespace, with their checksum files, any temporary files left by an interrupted write, and the GeoPackage files written by cacs_acs_prefetch(write_gpkg = TRUE), from the cache folder returned by cacs_cache_dir(). Other files in the folder and the subfolders themselves are kept. A folder given in the cache_dir argument of another function is not changed; to clear such a folder, first set the option to it, as in options(catchmentACS.cache_dir = "path/to/folder").

Usage

cacs_clear_cache(
  namespace = c("all", "isochrone", "acs", "acs_test", "intersect"),
  confirm = interactive()
)

Arguments

namespace

A string naming the kind of saved result to delete, which is also the name of its subfolder:

"all" (the default)

All four kinds.

"isochrone"

Drive-time areas saved by cacs_isochrone().

"acs"

American Community Survey (ACS) data saved by cacs_acs_prefetch().

"acs_test"

ACS data saved in test mode (see namespace_mode in cacs_get_cache_state()).

"intersect"

Results saved by cacs_intersect_weight().

confirm

A logical value. If TRUE, a question is asked first, and files are deleted only if the answer is yes; in a non-interactive session nobody can answer, so nothing is deleted. If FALSE, files are deleted without a question. The default, interactive(), is TRUE only in an interactive session, so a script run with Rscript deletes without asking. The question is also skipped when the environment variable CACS_NO_CONFIRM is "1".

Value

A tibble, returned invisibly, with one row for each subfolder cleared and the columns namespace, n_removed (the number of files deleted, counting a saved result, its checksum file, and its GeoPackage file as separate files), and bytes_freed (their total size in bytes). It has no rows when the cache folder does not exist or the answer to the question is no.

Details

After deleting, cacs_clear_cache() sets the hit and miss counts of the cleared subfolders to zero (see cacs_get_cache_state()). If the cache folder does not exist, a message says so and nothing is deleted.

Examples

# Use a temporary cache folder, so that a cache folder you have set is
# left alone
old <- options(catchmentACS.cache_dir = file.path(tempdir(), "cacs-example"))
cacs_cache_status()
#> # A tibble: 4 × 9
#>   namespace n_entries orphan_tmp n_fingerprints orphan_fingerprint_tmp
#>   <chr>         <int>      <int>          <int>                  <int>
#> 1 isochrone         0          0              0                      0
#> 2 acs               0          0              0                      0
#> 3 acs_test          0          0              0                      0
#> 4 intersect         0          0              0                      0
#> # ℹ 4 more variables: legacy_entries <int>, total_size_mb <dbl>, oldest <dttm>,
#> #   newest <dttm>
cacs_clear_cache("isochrone", confirm = FALSE)
#> Cache directory does not exist; nothing to clear.
#> ℹ Path: /tmp/RtmpMhGiu5/cacs-example
options(old)