I have a list of functions and I'd like to me able to call them without them being independent objects. For example:
funcs <- list(foo = function(a, b) a + b,
## in a list, how can I call `foo` from `bar`?
bar = function(m) foo(m, m/2))
I'm looking for something akin to moving up and over in a directory from the current location (e.g. ../foo
) but as a function call.
Some context:
There is a package that has some predefined modeling elements. There have been some requests for new features that would require to know the range of parameter values. Those are current encoded in functions in a list. For example, for partial least squares, the parameter values can range between 1 and the number of predictors in the data set:
modelInfo <- list(## other list elements
grid = function(x, y, len = NULL, search = "grid") {
if(search == "grid") {
out <- data.frame(ncomp = seq(1, min(ncol(x) - 1, len), by = 1))
} else {
out <- data.frame(ncomp = unique(sample(1:ncol(x), replace = TRUE)))
}
out
},
## more list elements
)
I'd like to add a list element called bounds
that will encode the possible values and have grid
references them. I could pass in the bounds
function data into grid
but that would add new arguments and break a lot of backwards compatibility. I didn't think that any other solution would be possible to reference bounds
from grid
without a significant change in code.