call_method: Call method

Description Usage Arguments Value Examples

Description

Call a particular set of methods (functions)

Usage

1
call_method(method, env = parent.frame())

Arguments

method

String, naming method to call

env

Environment with method arguments.

Value

Returns output from method.

Examples

 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)

mkearney/callmethod documentation built on May 9, 2019, 5:53 a.m.