subsettable | R Documentation |
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.
## S3 method for class 'subsettable_type'
x$name
## S3 method for class 'subsettable_which'
x$name
x |
A |
name |
The value to use for the |
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.