call_match | R Documentation |
call_match()
is like match.call()
with these differences:
It supports matching missing argument to their defaults in the function definition.
It requires you to be a little more specific in some cases. Either all arguments are inferred from the call stack or none of them are (see the Inference section).
call_match(
call = NULL,
fn = NULL,
...,
defaults = FALSE,
dots_env = NULL,
dots_expand = TRUE
)
call |
A call. The arguments will be matched to |
fn |
A function definition to match arguments to. |
... |
These dots must be empty. |
defaults |
Whether to match missing arguments to their defaults. |
dots_env |
An execution environment where to find dots. If
supplied and dots exist in this environment, and if |
dots_expand |
If Note that the resulting call is not meant to be evaluated since R
does not support passing dots through a named argument, even if
named |
When call
is not supplied, it is inferred from the call stack
along with fn
and dots_env
.
call
and fn
are inferred from the calling environment:
sys.call(sys.parent())
and sys.function(sys.parent())
.
dots_env
is inferred from the caller of the calling
environment: caller_env(2)
.
If call
is supplied, then you must supply fn
as well. Also
consider supplying dots_env
as it is set to the empty environment
when not inferred.
# `call_match()` supports matching missing arguments to their
# defaults
fn <- function(x = "default") fn
call_match(quote(fn()), fn)
call_match(quote(fn()), fn, defaults = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.