Description Usage Arguments Value Examples
Call a particular set of methods (functions)
1 | call_method(method, env = parent.frame())
|
method |
String, naming method to call |
env |
Environment with method arguments. |
Returns output from method.
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 | ## define method
r_norm <- function(n, m = 0, sd = 1) call_method("r_norm")
## set default
r_norm.default <- function(...) rnorm(...)
## call method
r_norm(10, 3)
## define method
rstring <- function(n, collapse = "") call_method("random_string")
## define method default
random_string.default <- function(...) {
list(...)[[1]]
}
## define method for numeric
random_string.numeric <- function(...) {
dots <- list(...)
n <- dots[[1]]
collapse <- dots[[2]]
fl <- sample(letters, 2, replace = TRUE)
paste(c(fl[1],
sample(c(rep(0:9, 3), letters, toupper(letters)), n - 2, replace = TRUE),
fl[2]), collapse = collapse)
}
## call method
rstring(20)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.