[R] Error with named definition argument to match.call

William Dunlap wdunlap at tibco.com
Wed Jul 16 02:38:46 CEST 2014


> So you are saying to make sense this would need to be
>
> > match.call(definition=g , call=quote(g(1)) )
> g(x = 1)

Yes.  What would you expect to get from match.call() outside of a
function if you don't give it a call argument?  It uses the default value
for 'call', sys.call(sys.parent()), but sys.parent() gives 0 at the
top level, the
same as when it is called from a function called from the top level, so the
default value of call is not useful when match.call is called from the
top level.
.


Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, Jul 15, 2014 at 5:19 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Jul 15, 2014, at 5:04 PM, William Dunlap wrote:
>
>> Does it make sense to call match.call outside of a function without
>> specifying both the function definition and the call to the function?
>
>
> My puzzlement came from the different response to these two commands:
>
> match.call(g)
> match.call(definition=g)
>
> I thought they would be the same. So you are saying to make sense this would
> need to be
>
>> match.call(definition=g , call=quote(g(1)) )
> g(x = 1)
>
>
>
> --
> David.
>
>
>> I agree that the error message is misleading.  Also, the return value
>> when call is not supplied does not seem useful, although it is
>> possible that it is correct in some technical sense.
>>
>>> match.call(definition=function(FirstArg, SecondArg)NULL,
>>> quote(anyFuncName(S=2, 1)))
>>
>> anyFuncName(FirstArg = 1, SecondArg = 2)
>>>
>>> match.call(function(FirstArg, SecondArg)NULL, quote(anyFuncName(S=2, 1)))
>>
>> anyFuncName(FirstArg = 1, SecondArg = 2)
>>>
>>> # without supplying 'call':
>>> match.call(definition=function(FirstArg, SecondArg)NULL)
>>
>> Error in match.call(definition, call, expand.dots) :
>>  unused argument (definition = function(FirstArg, SecondArg) NULL)
>>>
>>> match.call(function(FirstArg, SecondArg)NULL)
>>
>> match.call(FirstArg = function(FirstArg, SecondArg) NULL)
>>
>>
>>
>>
>>
>>
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>>
>> On Tue, Jul 15, 2014 at 4:27 PM, David Winsemius <dwinsemius at comcast.net>
>> wrote:
>>>
>>> The help page says:
>>>
>>> "Calling match.call outside a function without specifying definition is
>>> an
>>> error."
>>>
>>> And yet when I send a function with a 'definition' argument it errors:
>>>
>>>> g
>>>
>>> function(x, y=NULL, z=NULL) invisible(NULL)
>>>>
>>>> match.call(definition=g)
>>>
>>> Error in match.call(definition, call, expand.dots) :
>>>  unused argument(s) (definition = g)
>>>
>>> I wondered if this had something to do with primitive functions and their
>>> ignoring names but:
>>>
>>>> is.primitive(match.call)
>>>
>>> [1] FALSE
>>>
>>> Calling with an unnamed first argument succeeds:
>>>
>>>> match.call(g )
>>>
>>> match.call(x = g)
>>> --
>>>
>>> David Winsemius, MD
>>> Alameda, CA, USA
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>
>
> David Winsemius, MD
> Alameda, CA, USA
>



More information about the R-help mailing list