User defined function to yield successive records in the
stream. The FunctionProducer function must return an object
of length 0 (e.g., logical(0)) when the stream is complete.
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 Producer-class
or Consumer-class constructors.
state
Any information, made available to RESET.
Constructors
Use FunctionProducer or FunctionConsumer to construct
instances of this class.
Methods
See Producer and Consumer Methods.
Internal Class Fields and 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().
## 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)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Streamer)
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/Streamer/FunctionProducerConsumer-classes.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Function*
> ### Title: Classes for user-defined Producers and Consumers
> ### Aliases: Function* FunctionProducerConsumer-classes FunctionProducer
> ### FunctionProducer-class FunctionConsumer FunctionConsumer-class
> ### Keywords: classes
>
> ### ** Examples
>
> ## 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)
[1] 15072
> head(result)
[1] 0.5053140 0.5057702 0.5349482 0.4751352 0.5840785 0.5205261
>
> ## 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)
[1] 4236
> head(result)
[1] 2.270060 3.112534 2.085345 1.800820 2.779226 2.826138
>
>
>
>
>
> dev.off()
null device
1
>