Displaying 2 results from an estimated 2 matches for "call_match".
Did you mean:
call_macho
2024 Feb 17
2
Capturing Function Arguments
...ed scripts as part of a
unit testing framework.
I can capture the values fine, but I'm having trouble evaluating them
as if `force()` had been applied to each of them.
Here is a minimal example:
f0 <- function(x, y = 2 * z, z, a = NULL, b) NULL
f <- function(...) {
call <- rlang::call_match(fn = f0, defaults = TRUE)
args <- rlang::call_args(call)
# do something here to evaluate args as if force() had been called
# I've tried many things but haven't found a solution that handled everything
args
}
# In the below example args1 and args2 should be the same
a <- 1
ar...
2024 Feb 18
1
Capturing Function Arguments
...of the
function as it is running:
f0 <- function(arg = frobnicate()) {
frobnicate <- switch(
sample.int(3, 1),
function() environment(),
function(n=1) runif(n),
function() alist(a=)$a
)
arg
}
(And some arguments aren't meant to be evaluated at all.)
Even starting with rlang::call_match(call = NULL, defaults = TRUE) is
doomed to a certain extent because it gives you f(x = a, a = NULL) for
both function(x, a = NULL), f(a) (where `a` passed as an argument `x`
and `a` should be taken from the parent frame) and function(x = a, a =
NULL), f() (in which case `x` defaults to `a`, which i...