RE: match.call

Mark Bravington FSMG CEFAS (M.V.BRAVINGTON@cefas.co.uk)
Thu, 08 Jan 1998 09:38:04 +0100


Yesterday there was an enquiry about how to record the call by which a
function was invoked, including values for all the default parameters
etc. (I have lost the original query so am replying to the newslist).
The aim was to include this object as the "call" component of the
returned list. The standard method is just

my.call_ sys.call()

but this doesn't tell the full story with default parameters, nor does
it add names to any un-named parameters. Using "match.call" instead
does give you names, but again default parameters are excluded.

The following bit of code is cumbersome, but seems to do the job as
requested. There may be more succinct ways:

# Info on actual call:
a_ match.call( expand.dots=T)

# Info on default parameters:
sf_ sys.function()
mode( sf)_ 'list'
sf[[ length( sf)]]_ NULL # get rid of function body

# Now replace non-default parameters
for( i in names( a)[-1])
sf[[ i]]_ a[[ i]]

# "..." parameters will already have been inserted, so
sf$..._ NULL

# add name (or definition) of function being called
sf_ c( a[[1]], sf)

mode( sf)_ 'call'
sf

Hope this is useful.

Mark Bravington
m.v.bravington@cefas.co.uk