skip_run_if: Skip code

Description Usage Arguments Value Examples

View source: R/skip-run.R

Description

Skip code if all conditions are fulfilled. The code should not return anything.

Usage

1
skip_run_if(code, cond = NULL, files = NULL, timing = TRUE)

Arguments

code

Code to run. Do not forget to wrap it with { }.

cond

Condition to be fulfilled to skip running code. Default is NULL (not used). Should evaluate to either TRUE or FALSE 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 running code.

timing

Whether to print timing of running code? Default is TRUE.

Value

NULL, invisibly.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 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))

# 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)

runonce documentation built on Oct. 2, 2021, 9:06 a.m.