Description Usage Arguments Details Value Author(s) See Also Examples
This function defines new derivatives of the Stage
class. It is
a wrapper around setClass
and thus has a similar
interface.
1 2 | setStage(name, dispname = name, intype = "ANY", outtype = intype,
where = topenv(parent.frame()))
|
name |
The name of the stage, i.e., the role string |
dispname |
The name for display in a user interface |
intype |
The class of the data that protocols of this stage accept as input |
outtype |
The class of the data that protocols of this stage accept as output |
where |
The environment in which to define the stage class |
Calling setStage
defines two classes:
A derivative of Stage
that represents
this stage
A derivative of Protocol
from which
all protocols that implement this stage derive
For example, if we had a stage named “average”,
calling setStage
would create the classes StageAverage
and ProtoAverage
.
The function also defines a generic, named by the name
argument, that performs a protocol of this stage. There is a method
that takes an object of type intype
as first argument and a
method name as its second. Additional arguments are passed to
the perform
method of the protocol. In our prior example, there
would be a generic called average
and
method average,numeric
if intype
was given as
“numeric”.
It also defines a generic of the form nameProto
that serves
as an accessor for protocols of this stage. A method is defined for
Pipeline
and outtype
, so that one could retrieve our
“average” protocol with averageProto(pipeline)
or
averageProto(result)
. Similarly, a replacement generic and
methods are defined.
The name of the role
Michael Lawrence
The Stage
class; setProtocol
for
defining a new type of protocol
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 27 28 29 30 | ## simplest definition
setStage("average")
## add a display name and specialize to numeric input
setStage("average", "Average Vector", intype = "numeric")
setProtocol("mean", fun = mean, parent = "average")
setProtocol("quantile", representation = list(probs = "numeric"),
fun = quantile, parent = "average")
setProtocol("range", representation = list(low = "numeric", high = "numeric"),
fun = function(x, low = 0, high = Inf) x[x >= low & x <= high],
parent = setStage("trim", intype = "numeric"))
## Class Stage derivative
showClass("StageAverage")
## Class Protocol derivative
showClass("ProtoAverage")
## generic defined
showMethods("average")
# try this generic method
d <- c(1, 2, 4)
average(d, "mean")
## create a pipeline
p <- Pipeline("trim", "average")
res <- perform(p, d)
res
## generic *Proto
averageProto(p)
averageProto(res)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.