Skip to contents

Clean up orderly draft and data directories. Deletes all drafts (possibly just for a set of report names) and then deletes dangling data sets that are not pointed to by any draft or committed reports. Running cleanup does not affect any reports that have been committed with orderly_commit() (i.e., the contents of the archive/ directory).

Usage

orderly_cleanup(
  name = NULL,
  root = NULL,
  locate = TRUE,
  draft = TRUE,
  data = TRUE,
  failed_only = FALSE
)

Arguments

name

Optional name; in this case only clean up drafts with this name

root

The path to an orderly root directory, or NULL (the default) to search for one from the current working directory if locate is TRUE.

locate

Logical, indicating if the configuration should be searched for. If TRUE and config is not given, then orderly looks in the working directory and up through its parents until it finds an orderly_config.yml file.

draft

Logical, indicating if drafts should be removed

data

Logical, indicating if dangling data should be removed (data not used by any draft or archived report).

failed_only

Delete only failed reports (those without the end-of-run metadata). This will also clean up drafts created by orderly_test_start()

Value

No return value, this function is called only for its side effects

Examples

# In a new example orderly, run two reports and commit only the
# second one:
path <- orderly::orderly_example("minimal")
id1 <- orderly::orderly_run("example", root = path)
#> [ name       ]  example
#> [ id         ]  20220118-093838-cd9297b7
#> [ start      ]  2022-01-18 09:38:38
#> [ data       ]  source => dat: 20 x 2
#> 
#> > png("mygraph.png")
#> 
#> > par(mar = c(15, 4, 0.5, 0.5))
#> 
#> > barplot(setNames(dat$number, dat$name), las = 2)
#> 
#> > dev.off()
#> agg_png 
#>       2 
#> [ end        ]  2022-01-18 09:38:38
#> [ elapsed    ]  Ran report in 0.04175305 secs
#> [ artefact   ]  mygraph.png: f8f77b71be1e3a2c8c9a27396905d549
id2 <- orderly::orderly_run("example", root = path)
#> [ name       ]  example
#> [ id         ]  20220118-093838-e71de068
#> [ start      ]  2022-01-18 09:38:38
#> [ data       ]  source => dat: 20 x 2
#> 
#> > png("mygraph.png")
#> 
#> > par(mar = c(15, 4, 0.5, 0.5))
#> 
#> > barplot(setNames(dat$number, dat$name), las = 2)
#> 
#> > dev.off()
#> agg_png 
#>       2 
#> [ end        ]  2022-01-18 09:38:38
#> [ elapsed    ]  Ran report in 0.03889489 secs
#> [ artefact   ]  mygraph.png: f8f77b71be1e3a2c8c9a27396905d549
orderly::orderly_commit(id2, root = path)
#> [ commit     ]  example/20220118-093838-e71de068
#> [ copy       ]
#> [ import     ]  example:20220118-093838-e71de068
#> [ success    ]  :)
#> [1] "/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpMWUKEw/file17e35dc97b1b/archive/example/20220118-093838-e71de068"

# We now have one draft and one archive report:
orderly::orderly_list_drafts(root = path)
#>      name                       id
#> 1 example 20220118-093838-cd9297b7
orderly::orderly_list_archive(root = path)
#>      name                       id
#> 1 example 20220118-093838-e71de068

# To clean up the drafts:
orderly::orderly_cleanup(root = path)
#> [ clean      ]  Found 1 draft report
#> [ clean      ]  /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpMWUKEw/file17e35dc97b1b/draft/example/20220118-093838-cd9297b7
#> [ clean      ]  Found 0 csv files
#> [ clean      ]  Found 0 rds files

# We now have no draft and one archive reports:
orderly::orderly_list_drafts(root = path)
#> [1] name id  
#> <0 rows> (or 0-length row.names)
orderly::orderly_list_archive(root = path)
#>      name                       id
#> 1 example 20220118-093838-e71de068