Skip to contents

Find, and delete, file that were generated by running a report. Until you're comfortable with what this will do, you are strongly recommended to run orderly_cleanup_status first to see what will be deleted.

Usage

orderly_cleanup(name = NULL, dry_run = FALSE, root = NULL)

orderly_cleanup_status(name = NULL, root = NULL)

Arguments

name

Name of the report directory to clean (i.e., we look at src/<name> relative to your orderly root

dry_run

Logical, indicating if we should not delete anything, but instead just print information about what we would do

root

The path to the root directory, or NULL (the default) to search for one from the current working directory. This function does require that the directory is configured for orderly, and not just outpack (see orderly_init for details).

Value

An (currently unstable) object of class orderly_cleanup_status within which the element delete indicates files that would be deleted (for orderly_cleanup_status) or that were deleted (for orderly_cleanup)

Details

After file deletion, we look through and remove all empty directories; orderly2 has similar semantics here to git where directories are never directly tracked.

For recent gert we will ask git if files are ignored; if ignored then they are good candidates for deletion! We encourage you to keep a per-report .gitignore that lists files that will copy into the source directory, and then we can use that same information to clean up these files after generation. Importantly, even if a file matches an ignore rule but has been committed to your repository, it will no longer match the ignore rule.

Notes for user of orderly1

In orderly1 this function has quite different semantics, because the full set of possible files is always knowable from the yaml file. So there, we start from the point of view of the list of files then compare that with the directory.

Examples

# Create a simple example:
path <- orderly2::orderly_example("default")
#>  Created orderly root at '/tmp/Rtmpl7F6gT/orderly2_ex_1d2c4ba9d472'

# We simulate running a packet interactively by using 'source';
# you might have run this line-by-line, or with the "Source"
# button in Rstudio.
source(file.path(path, "src/data/data.R"), chdir = TRUE)

# Having run this, the output of the report is present in the
# source directory:
fs::dir_tree(path)
#> /tmp/Rtmpl7F6gT/orderly2_ex_1d2c4ba9d472
#> ├── orderly_config.yml
#> └── src
#>     └── data
#>         ├── data.R
#>         └── data.rds

# We can detect what might want cleaning up by running
# "orderly_cleanup_status":
orderly2::orderly_cleanup_status("data", root = path)
#>  data is not clean:
#>  1 file can be deleted by running 'orderly2::orderly_cleanup("data")':
#> • data.rds

# Soon this will print more nicely to the screen, but for now you
# can see that the status of "data.rds" is "derived", which means
# that orderly knows that it is subject to being cleaned up; the
# "delete" element shows what will be deleted.

# Do the actual deletion:
orderly2::orderly_cleanup("data", root = path)
#>  Deleting 1 file from 'data':
#> • data.rds

fs::dir_delete(path)