amatch(definition, call) match.call(definition=<<see below>>, call=<<see below>>, expand.dots=T)
match.call
when it is called from inside
another function; the default is the function that calls
match.call
.
definition
.
This is optional for
match.call
when it is called from inside
another function; the default is the call of the
function that calls
match.call
.
TRUE
, then a call involving the
...
construct will
have the arguments corresponding to
...
separated by commas along with the other arguments.
If it is
FALSE
, then the
...
arguments will all be grouped together in
a list.
amatch
returns a list of the arguments, matched as they would
be by the evaluator if
the call were made to the function in
definition
.
The list is in the order that the arguments appear in
definition
.
The value has attributes
names
,
which gives the formal names of the arguments,
and
missing
, which
tells whether the corresponding argument
was omitted from
call
(regardless of whether a default appears in the
definition).
match.call
returns a call in which all of the arguments are specified by
name.
Therefore, components of this object corresponding to argument names in the
definition will be the actual, unevaluated argument if one was given, or else
NULL
.
A particularly common use is to get the call of the current function,
with arguments named.
Aside from its role in the semantic model,
amatch
is chiefly used by
functions that want to pre-match arguments in order to do something
special about evaluation.
Generally,
match.call
is the more convenient way to get at the
explicit argument expressions in a call.
Note that functions
sys.call
and
sys.function
are general ways to
get at a functions own call and definition.
match
,
charmatch
are
other matching functions. To convert a call into a string, use
deparse
(useful for making plot titles out of calls). Use
eval
to reevaluate the call, perhaps with different data.
call
can be an unevaluated call to a
function other than that given in the definition.
However this is not recommended, as any error messages that occur
may be misleading, by referring to incorrect function names.
sys.call
returns an object of class call,
like
match.call
. The difference is
that
sys.call
returns the actual call,
with argument names missing or abbreviated.
Use
match.call
when creating a
call
component or attribute,
otherwise functions such as
update
may fail.
amatch(function(x = 2, y = 3, abc = "hi", ...){}, expression(fun(x1, ab = 7, c = x2))) # this produces the following output: $x: .Argument(x1, x = 2) $y: .Argument(, y = 3) $abc: [1] 7 $...: .Argument((c = x2), ... = ) attr(, "missing"): [1] F T F F # Return a matched version of my own call as an attribute myfunction <- function(formula, data, weights, subset, ...){ value <- "Not computed" attr(value, "call") <- match.call() value } myfunction(data=solder, skips ~ Mask, plot = F) [1] "Not computed" attr(, "call"): myfunction(formula = skips ~ Mask, data = solder, plot = F) # 3rd example: match.call(get, expression(get("abc", w=2))) # gives the output: get(name = "abc", where = 2) # 4th example: match.call(rm, expression(rm(foo1, foo2))) rm(foo1, foo2) # 5th example: match.call(rm, expression(rm(foo1, foo2)), expand.dots=F) rm(... = list(foo1, foo2))