Learn R Programming

svMisc (version 0.9-68)

batch: Run a function in batch mode

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

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

concept

batch processing

See Also

progress

Examples

Run this code
## Here is a fake batcheable process
fakeProc <- function (file) {
    message("Processing ", file, "...")
    flush.console()
    Sys.sleep(1)
    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)

Run the code above in your browser using DataLab