batch: Run a function in batch mode

Description Usage Arguments Author(s) 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 return TRUE in case of success, or FALSE otherwise.

Usage

1
2
batch(items, fun, ..., show.progress = !isAqua() && !isJGR(),
    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 and 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 batcheable function suppressed? Only warnings will be issued. Recommended if show.progress = TRUE.

verbose

display start and end messages if TRUE (default).

Author(s)

Philippe Grosjean <[email protected]>

See Also

progress

Examples

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

## Run it in batch mode on five items
files <- paste("file", 1:5, sep = "")
batch(files, fakeProc)

svMisc documentation built on May 29, 2017, 12:18 p.m.