Skip code if all conditions are fulfilled. The code should not return anything.
Arguments
- code
Code to run. Do not forget to wrap it with
{ }
.- cond
Condition to be fulfilled to skip running
code
. Default isNULL
(not used). Should evaluate to eitherTRUE
orFALSE
otherwise.- files
Character vector of file path(s). Default is
NULL
(not used). This function checks if all these files exist, and if they all do exist, it skips runningcode
.- timing
Whether to print timing of running code? Default is
TRUE
.
Examples
# Prepare some temporary file
tmp <- tempfile(fileext = ".txt")
# Run once because file does not exist yet
skip_run_if({
Sys.sleep(2)
write.table(iris, tmp)
}, cond = file.exists(tmp))
#> user system elapsed
#> 0.00 0.00 2.04
# Skip run because `cond` is `TRUE`
skip_run_if({
Sys.sleep(2)
write.table(iris, tmp)
}, cond = file.exists(tmp))
# Skip run because file exists
skip_run_if({
Sys.sleep(2)
write.table(iris, tmp)
}, files = tmp)