I have a function that can take a list in one of its arguments. I would like to be able to manipulate this list in the function but without having the elements of the list evaluated.
For example, if I have this:
external <- list("a" = mean, "foo" = sum)
foo <- function(x) {
rlang::get_expr(x)
}
Then when I call foo(external)
, I’d like to have an object that I can manipulate inside foo()
like:
$a
mean
$foo
sum
where mean
and sum
are symbols. So far, I have that:
foo(external)
#> $a
#> function (x, ...)
#> UseMethod("mean")
#> <bytecode: 0x58773e2c7020>
#> <environment: namespace:base>
#>
#> $foo
#> function (..., na.rm = FALSE) .Primitive("sum")
but that isn’t what I’d like to have since the functions in the list are evaluated.
Is this possible? I’m ok with base
or rlang
solutions.