I have a set of small functions that generate random strings similar to rnorm or sample . All these functions have common arguments, for simplicity we can say that one common argument is n . I would like to make a large function (functional) that takes n as and the argument plus ... , which can be any of the small functions. This meta-function evaluates small functions using the set n if they have this argument. here is an example:
## LITTLE FUNCTIONS
fun1 <- function(n, x = 1:10) sample(x, n, TRUE) fun2 <- function(n, x = LETTERS) sample(x, n, TRUE) fun3 <- function(n, x = 50) rnorm(n, x) fun4 <- function(n, x = 100, y = 10) rnorm(n, x, y)
FUNCTIONAL (META FUNCTION)
combiner <- function(n, ...){
I would like it to evaluate functions even if they are missing () , as is the case with fun2 above, but this is more suitable. I think this is possible because magrittr pipes can do this .
## DESIRED EXIT
list( fun1(6), fun2(6), rnorm(6), fun4(6, y=8) ) ## OUTPUT IS SEED DEPENDANT ## [[1]] ## [1] 2 1 6 6 1 1 ## ## [[2]] ## [1] "V" "Z" "A" "F" "F" "G" ## ## [[3]] ## [1] -0.91932716 -0.05833169 1.75440750 2.19959565 -0.11145315 1.32216601 ## ## [[4]] ## [1] 107.48747 89.55798 93.15771 111.32380 100.82104 104.07829
source share