Description Usage Arguments Constructors Methods Internal Class Fields and Methods Author(s) See Also Examples
The FunctionProducer
and FunctionConsumer
classes
provide an easy way to quickly create Producer
and
Consumer
instances from user-provided functions.
1 2 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.