Learn R Programming

drake (version 7.5.2)

clean: Remove targets/imports from the cache.

Description

Cleans up the work done by make().

Usage

clean(..., list = character(0), destroy = FALSE, path = NULL,
  search = NULL, cache = drake::drake_cache(path = path, verbose =
  verbose), verbose = 1L, jobs = 1, force = FALSE,
  garbage_collection = FALSE, purge = FALSE)

Arguments

...

Targets to remove from the cache: as names (symbols) or character strings. If the tidyselect package is installed, you can also supply dplyr-style tidyselect commands such as starts_with(), ends_with(), and one_of().

list

Character vector naming targets to be removed from the cache. Similar to the list argument of remove().

destroy

Logical, whether to totally remove the drake cache. If destroy is FALSE, only the targets from make() are removed. If TRUE, the whole cache is removed, including session metadata, etc.

path

Path to a drake cache (usually a hidden .drake/ folder) or NULL.

search

Deprecated.

cache

drake cache. See new_cache(). If supplied, path is ignored.

verbose

Integer, control printing to the console/terminal.

  • 0: print nothing.

  • 1: print targets, retries, and failures.

  • 2: also show a spinner when preprocessing tasks are underway.

jobs

Number of jobs for light parallelism (disabled on Windows).

force

Logical, whether to try to clean the cache even though the project may not be back compatible with the current version of drake.

garbage_collection

Logical, whether to call cache$gc() to do garbage collection. If TRUE, cached data with no remaining references will be removed. This will slow down clean(), but the cache could take up far less space afterwards. See the gc() method for storr caches.

purge

Logical, whether to remove objects from metadata namespaces such as "meta", "build_times", and "errors".

Value

Invisibly return NULL.

Safeguards

If you run clean() with no arguments, drake's response is to remove all the targets etc. from the cache. To prevent you from doing this accidentally in an interactive session, clean() prompts you with a menu to confirm. The menu only appears once per session. You can disable it with options(drake_clean_menu = FALSE).

Details

By default, clean() removes references to cached data. To deep-clean the data to free up storage/memory, use clean(garbage_collection = TRUE). Garbage collection is slower, but it purges data with no remaining references. To just do garbage collection without cleaning, see drake_gc(). Also, for clean(), you must be in your project's working directory or a subdirectory of it. WARNING: This deletes ALL work done with make(), which includes file targets as well as the entire drake cache. Only use clean() if you're sure you won't lose anything important.

See Also

drake_gc(), make()

Examples

Run this code
# NOT RUN {
isolate_example("Quarantine side effects.", {
if (suppressWarnings(require("knitr"))) {
load_mtcars_example() # Get the code with drake_example("mtcars").
make(my_plan) # Run the project, build the targets.
# List objects in the cache, excluding R objects
# imported from your workspace.
cached(no_imported_objects = TRUE)
# Remove 'summ_regression1_large' and 'small' from the cache.
clean(summ_regression1_large, small)
# Those objects should be gone.
cached(no_imported_objects = TRUE)
# Rebuild the missing targets.
make(my_plan)
# Remove all the targets and imports.
# On non-Windows machines, parallelize over at most 2 jobs.
clean(jobs = 2)
# Make the targets again.
make(my_plan)
# Garbage collection removes data whose references are no longer present.
# It is slow, but you should enable it if you want to reduce the
# size of the cache.
clean(garbage_collection = TRUE)
# All the targets and imports are gone.
cached()
# But there is still cached metadata.
build_times()
# To make even more room, use the "purge" flag.
clean(purge = TRUE)
build_times()
# Completely remove the entire cache (default: '.drake/' folder).
clean(destroy = TRUE)
}
})
# }

Run the code above in your browser using DataLab