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, locate = TRUE)
orderly_cleanup_status(name = NULL, root = NULL, locate = TRUE)
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 iflocate
isTRUE
. This function does require that the directory is configured for orderly, and not just outpack (see orderly_init for details).- locate
Logical, indicating if the configuration should be searched for. If
TRUE
andconfig
is not given, then orderly looks in the working directory and up through its parents until it finds an.outpack
directory
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
(not yet on CRAN) 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/RtmprnCT52/file17165bf69e46'
# 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)
#> Warning: cannot open file '/tmp/RtmprnCT52/file17165bf69e46/src/data/data.R': No such file or directory
#> Error in file(filename, "r", encoding = encoding): cannot open the connection
# Having run this, the output of the report is present in the
# source directory:
fs::dir_tree(path)
#> Error: [ENOENT] Failed to search directory '/tmp/RtmprnCT52/file17165bf69e46': no such file or directory
# We can detect what might want cleaning up by running
# "orderly_cleanup_status":
orderly2::orderly_cleanup_status("data", root = path)
#> Error in orderly_src_root(root, locate, call = environment()): Directory does not exist: '/tmp/RtmprnCT52/file17165bf69e46'
# 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)
#> Error in orderly_src_root(root, locate, call = environment()): Directory does not exist: '/tmp/RtmprnCT52/file17165bf69e46'