Function* {Streamer} | R Documentation |
The FunctionProducer
and FunctionConsumer
classes
provide an easy way to quickly create Producer
and
Consumer
instances from user-provided functions.
FunctionProducer(FUN, RESET, ..., state=NULL) FunctionConsumer(FUN, RESET, ..., state=NULL)
FUN |
User defined function to yield successive records in the
stream. The |
RESET |
An optional function of one arugment (‘state’) to reset the stream to its original state. If missing, the stream cannot be reset. |
... |
Arguments passed to the |
state |
Any information, made available to |
Use FunctionProducer
or FunctionConsumer
to construct
instances of this class.
See Producer
and Consumer
Methods.
Internal fields of this class are are described with, e.g.,
getRefClass("FunctionProducer")$fields
.
Internal methods of this class are described with
getRefClass("FunctionProducer")$methods()
and
getRefClass("FunctionProducer")$help()
.
Nishant Gopalakrishnan ngopalak@fhcrc.org
## A ProducerFunction producerFun <- function() ## produce the mean of 10 random uniform numbers ## stop when the mean is greater than 0.8 { x <- mean(runif(10)) if (x > .8) numeric(0) else x } randomSampleMeans <- FunctionProducer(producerFun) result <- sapply(randomSampleMeans, c) length(result) head(result) ## A FunctionConsumer: consumerFun <- function(y) ## transform input by -10 log10 { -10 * log10(y) } neg10log10 <- FunctionConsumer(consumerFun) strm <- Stream(randomSampleMeans, neg10log10) result <- sapply(strm, c) length(result) head(result)