skip_run_if {runonce}R Documentation

Skip code

Description

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

Usage

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

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


[Package runonce version 0.2.3 Index]