drake (version 6.2.1)

clean: Remove targets/imports from the cache.

Description

Cleans up the work done by make().

Usage

clean(..., list = character(0), destroy = FALSE, path = getwd(),
  search = TRUE, cache = NULL, verbose = drake::default_verbose(),
  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

Root directory of the drake project, or if search is TRUE, either the project root or a subdirectory of the project. Ignored if a cache is supplied.

search

logical. If TRUE, search parent directories to find the nearest drake cache. Otherwise, look in the current working directory only. Ignored if a cache is supplied.

cache

drake cache. See new_cache(). If supplied, path and search are ignored.

verbose

logical or numeric, control printing to the console. Use pkgconfig to set the default value of verbose for your R session: for example, pkgconfig::set_config("drake::verbose" = 2).

  • 0 or FALSE: print nothing.

  • 1 or TRUE: print only targets to build.

  • 2: also print checks and cache info.

  • 3: also print any potentially missing items.

  • 4: also print imports and writes to the cache.

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.

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. clean(search = TRUE) searches upwards in your folder structure for the drake cache and acts on the first one it sees. Use search = FALSE to look within the current working directory only. 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 {
test_with_dir("Quarantine side effects.", {
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.
names(read_drake_meta())
build_times()
# To make even more room, use the "purge" flag.
clean(purge = TRUE)
names(read_drake_meta())
build_times()
# Completely remove the entire cache (default: '.drake/' folder).
clean(destroy = TRUE)
})
# }

Run the code above in your browser using DataLab