vignettes/svBase.Rmd
svBase.Rmd
The $
operator is not suitable for functions in base R.
It is not meaningful in that context. Yet, it may be convenient to use
it in certain conditions. From the example of
?subsettable
:
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
#> 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"
# This function can be used as usual:
foo(rnorm(50), type = "histogram")
# ... but also this way:
foo$histogram(rnorm(50))
foo$boxplot(rnorm(50))