match.call
Argument Matching

Description

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

Usage

match.call(definition = sys.function(sys.parent()), call = sys.call(sys.parent()), 
           expand.dots = TRUE, envir = parent.frame(2L))

Arguments

definition a function. This argument is optional if match.call is called from inside another function, in which case the default is the function that calls match.call.
call an unevaluated call to the function given in definition. This argument is optional if match.call is called from inside another function, in which case the default is the call of the function that calls match.call.
expand.dots a logical flag. If TRUE (the default), a call involving the ... construct has the arguments corresponding to ..., separated by commas, along with the other arguments. If FALSE, the ... arguments are grouped together in a list, as the value of a single argument named ....
envir an environment used for retrieving the values of the ... argument in the call, if any. By default, if match.call is called from inside another function, this is the environment of the function that calls match.call.

Details

match.call is a convenient way to get at the explicit argument expressions in a call. Note that the following functions provide matching or general means to access a function's call and definition:
To convert a call into a string, use deparse, (It is useful for making plot titles out of calls). Use eval to reevaluate the call, perhaps with different data.
A common use for match.call is to get the call of the current function, with arguments named.
You can use call as an unevaluated call to a function other than that given in the definition; however, this usage is not recommended, because it can produce misleading error messages by referring to incorrect function names.
Value
returns a call in which all of the arguments are specified by name (except for unnamed actual values that match a ... argument). Therefore, components of this object corresponding to argument names in the definition are the actual, unevaluated argument, if one was given, or NULL.
Note
sys.call returns an object of class call, like match.call, except 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 can fail.
See Also
charmatch, deparse, eval, match, sys.call, sys.function
Examples
# 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
  }
mydata <- data.frame(x=1:10,y<-sin(1:10))
myfunction(data=mydata, y ~ x, plot = F)
# returns:
#   [1] "Not computed"
#   attr(, "call"):
#   myfunction(formula=y ~ x, data=mydata, plot=F)

# specify definition, call match.call(function(name,where,frame) NULL, expression(get("abc", w=2))) # returns: get(name = "abc", where = 2)

# function with ... arg match.call(function(...) NULL, expression(rm(foo1, foo2))) # returns: rm(foo1, foo2) match.call(function(...) NULL, expression(rm(foo1, foo2)), expand.dots=F) # returns: rm(... = list(foo1, foo2))

Package base version 6.1.1-7
Package Index