Argument Matching

DESCRIPTION:
Matches the arguments as would be done by a function call.

USAGE:
amatch(definition, call)
match.call(definition=<<see below>>, call=<<see below>>, expand.dots=T)

REQUIRED ARGUMENTS:
definition:
an S-PLUS function. This is optional for match.call when it is called from inside another function; the default is the function that calls match.call.
call:
an unevaluated call to the function given in 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.

OPTIONAL ARGUMENTS:
expand.dots:
logical flag: if 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.

VALUE:
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.


DETAILS:
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.


SEE ALSO:
charmatch , deparse , eval , match , sys.call , sys.function .

EXAMPLES:
amatch(function(x = 2, y = 3, abc = "hi", ...){},
       expression(fun(x1, ab = 7, c = x2)))

# this produces the following output: $x: amp;.Argument(x1, x = 2)

$y: amp;.Argument(, y = 3)

$abc: [1] 7

$...: amp;.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))