Producer-class: Class defining methods for all Producers

Description Usage Arguments Methods Internal Class Fields and Methods Author(s) See Also Examples

Description

A virtual class representing components that can read data from connections, and yield records to the user or a Consumer instance. A Producer represents a source of data, responsible for parsing a file or other data source into records to be passed to Consumer classes. Producer and Consumer instances are associated with each other through the Stream function.

Usage

1
2
3
4
5
## S4 method for signature 'Producer'
lapply(X, FUN, ...)

## S4 method for signature 'Producer'
sapply(X, FUN, ..., simplify=TRUE, USE.NAMES=TRUE)

Arguments

X

An instance of class Producer

FUN

A function to be applied to each successful yield() of X.

...

Additional arguments to FUN.

simplify

See ?base::sapply.

USE.NAMES

See ?base::sapply but note that names do not usually make sense for instances of class Producer.

Methods

Methods defined on this class include:

Stream

Construct a stream from one Producer and one or more Consumer. See ?Stream.

yield

Yield a single result (e.g., data.frame) from the Producer.

reset

Reset, if possible, the Producer.

lapply, sapply

Apply FUN to each result applied to yield(), simplifying (using simplify2array) if possible for sapply. Partial results on error can be recovered using tryCatch, as illustrated below. Infinite producers will of course exhaust memory.

Internal Class Fields and Methods

Internal fields of this class are are described with, e.g., getRefClass("Producer")$fields.

Internal methods of this class are described with getRefClass("Producer")$methods() and getRefClass("Producer")$help().

Author(s)

Martin Morgan [email protected]

See Also

Streamer-package, Consumer-class, Streamer-class.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
showClass("Producer")
showMethods(class="Producer", where="package:Streamer")

sapply(Seq(to=47, yieldSize=7), function(elt) {
    c(n = length(elt), xbar = mean(elt))
})

## recover partial results
fun = function(i) if (i == 5) stop("oops, i == 5") else i
res <- tryCatch(sapply(Seq(to=10), fun), error=function(err) {
    warning(conditionMessage(err),
            "\n  only partial results available")
    simplify2array(err$partialResult)
})
res

Streamer documentation built on Nov. 17, 2017, 10 a.m.