Description Usage Arguments Examples
In case a textual argument allows for selecting the result, for
instance, if plot()
allows for several charts that you can choose with a
type=
or which=
, making the function 'subsettable' also allows to
indicate fun$variant()
. See examples.
1 2 3 4 5 |
x |
A |
name |
The value to use for the |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | foo <- structure(function(x, type = c("histogram", "boxplot"), ...) {
type <- match.arg(type, c("histogram", "boxplot"))
switch(type,
histogram = hist(x, ...),
boxplot = boxplot(x, ...),
stop("unknow type")
)
}, class = c("function", "subsettable_type"))
foo
# This function can be used as usual:
foo(rnorm(50), type = "histogram")
# ... but also this way:
foo$histogram(rnorm(50))
foo$boxplot(rnorm(50))
|
Attaching package: ‘svMisc’
The following object is masked from ‘package:utils’:
?
function (x, type = c("histogram", "boxplot"), ...)
{
type <- match.arg(type, c("histogram", "boxplot"))
switch(type, histogram = hist(x, ...), boxplot = boxplot(x,
...), stop("unknow type"))
}
attr(,"class")
[1] "function" "subsettable_type"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.