Description Usage Arguments Methods Internal Class Fields and Methods Author(s) See Also Examples
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.
1 2 3 4 5 |
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.
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
|
Class "Producer" [package "Streamer"]
Slots:
Name: .xData
Class: environment
Extends:
Class "Streamer", directly
Class "envRefClass", by class "Streamer", distance 2
Class ".environment", by class "Streamer", distance 3
Class "refClass", by class "Streamer", distance 3
Class "environment", by class "Streamer", distance 4, with explicit coerce
Class "refObject", by class "Streamer", distance 4
Known Subclasses:
Class "ConnectionProducer", directly
Class "Seq", directly
Class "FunctionProducer", directly
Class "ScanProducer", by class "ConnectionProducer", distance 2
Class "ReadLinesProducer", by class "ConnectionProducer", distance 2
Class "ReadTableProducer", by class "ConnectionProducer", distance 2
Class "RawInput", by class "ConnectionProducer", distance 2
Function: Stream (package Streamer)
x="Producer"
Function: lapply (package BiocGenerics)
X="Producer"
Function: sapply (package BiocGenerics)
X="Producer"
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
n 7 7 7 7 7 7 5
xbar 4 11 18 25 32 39 45
Warning message:
In value[[3L]](cond) : yield(): oops, i == 5
only partial results available
[1] 1 2 3 4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.