Description Usage Arguments Value Examples
View source: R/build_factory.R
Easily Build Function Factories
1 | build_factory(fun, ..., .pass_dots = FALSE, .internal_variables = NULL)
|
fun |
A function to turn into a factory. |
... |
Arguments for the factory function. Things on the RHS will be
evaluated before building your factory unless explicitly quoted with
|
.pass_dots |
A logical indicating whether the factory should accept
additional arguments (...) to pass on to methods. In order for this to
work, the manufactured function *must* also include dots, and the input
|
.internal_variables |
A named list of additional code to run to create additional variables used by the factory. |
A function factory.
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 | y <- 2
power <- build_factory(
fun = function(x) {
x^exponent
},
exponent
)
square <- power(y)
square(2)
y <- 7
square(2)
base_bins <- build_factory(
.internal_variables = list(
nclass_fun = switch(
type,
Sturges = nclass.Sturges,
scott = nclass.scott,
FD = nclass.FD,
stop("Unknown type", call. = FALSE)
)
),
fun = function(x) {
(max(x) - min(x) / nclass_fun(x))
},
type
)
base_bins("Sturges")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.