Producer {Streamer} | R Documentation |
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.
## S4 method for signature 'Producer' lapply(X, FUN, ...) ## S4 method for signature 'Producer' sapply(X, FUN, ..., simplify=TRUE, USE.NAMES=TRUE)
X |
An instance of class |
FUN |
A function to be applied to each successful |
... |
Additional arguments to |
simplify |
See |
USE.NAMES |
See |
Methods defined on this class include:
Construct a stream from one Producer
and one or
more Consumer
. See ?Stream
.
Yield a single result (e.g., data.frame
) from
the Producer.
Reset, if possible, the Producer.
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 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()
.
Martin Morgan mtmorgan@fhcrc.org
Streamer-package
, Consumer-class
,
Streamer-class
.
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