batch: Run a function in batch mode

Description Usage Arguments Value See Also Examples

View source: R/batch.R

Description

A function can be run in batch mode if it never fails (replace errors by warnings) and returns TRUE in case of success, or FALSE otherwise.

Usage

1
2
3
4
5
6
7
8
batch(
  items,
  fun,
  ...,
  show.progress = !is_aqua() && !is_jgr(),
  suppress.messages = show.progress,
  verbose = TRUE
)

Arguments

items

The items (usually, arguments vector of character strings) on which to apply fun sequentially.

fun

The function to run (must return TRUE or FALSE and issue only warnings or messages to be a good candidate, batchable, function).

...

Further arguments to pass the fun.

show.progress

Do we show progression as item x on y... message? This uses the progress() function.

suppress.messages

Are messages from the batchable function suppressed? Only warnings will be issued. Recommended if show.progress = TRUE.

verbose

Display start and end messages if TRUE (default).

Value

Returns invisibly the number of items that were correctly processed with attributes items and ok giving more details.

See Also

progress()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
# Here is a fake batchable process
fake_process <- function(file) {
  message("Processing ", file, "...")
  flush.console()
  Sys.sleep(0.5)
  if (runif(1) > 0.7) { # Fails
    warning("fake_process was unable to process ", file)
    invisible(FALSE)
  } else invisible(TRUE)
}

# Run it in batch mode on five items
files <- paste0("file", 1:5)
batch(files, fake_process)

## End(Not run)

svMisc documentation built on Oct. 12, 2021, 1:08 a.m.