[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-devel
Subject:    Re: [Rd] Missing argument vs. empty argument
From:       Renaud Gaujoux <renaud () mancala ! cbio ! uct ! ac ! za>
Date:       2011-01-25 11:01:38
Message-ID: 4D3EAD92.5020108 () cbio ! uct ! ac ! za
[Download RAW message or body]

My purpose is indeed to write a '[' method.
I will go for the `[.data.frame` solution then.
Thank you.


On 25/01/2011 12:53, Prof Brian Ripley wrote:
> On Tue, 25 Jan 2011, Renaud Gaujoux wrote:
>
>> Hi,
>>
>> is there an easy, robust, and/or recommended way to distinguish a 
>> missing argument from an empty argument as in:
>
> An empty argument is a missing argument when argument matching is 
> done, e.g.
>
>> foo <- function(i,j) match.call()
>> foo(i)
> foo(i = i)
>> foo(i,)
> foo(i = i)
>> foo(,j)
> foo(j = j)
>
> It is rather against the spirit of R to use the actual call rather 
> than the matched call.  Unless you are doing this to write a '[' 
> method I would suggest you find a different convention, e.g. 
> distinguish f(i) and f(i, NULL).  For the exception, look at 
> `[.data.frame`, which does use nargs().
>
> (NB: what I have said does not apply to primitives like '[' itself, 
> which do not do standard argument matching.)
>
>
>>
>> foo <- function(i, j){
>>    print(missing(j))
>>    print(nargs())
>> }
>>
>> foo(i)  # TRUE, 1
>> foo(i,) # TRUE, 2
>>
>> I know I can work around with nargs, the list of arguments and the 
>> names of the passed arguments, but I wish there is something already 
>> in place for this.
>> This is specially important for '['-like methods where x[i,] is not 
>> the same as x[i].
>> What I am looking for is a function that tells me if an argument has 
>> actually been passed empty:
>>
>> foo <- function(i, j, k){
>>    print( empty.arg(j) )
>>    print(nargs())
>> }
>>
>> would result in:
>>
>> foo(i) # FALSE, 1
>> foo(i, ) # TRUE, 2
>> foo(i, j) # FALSE, 2
>> foo(i, k=2) # FALSE, 2
>> foo(i, k=2, ) # TRUE, 3
>>
>> Thank you for any help or pointer.
>>
>> Bests,
>> Renaud
>>
>>
>>
>>
>> ###
>> UNIVERSITY OF CAPE TOWN This e-mail is subject to the UCT ICT 
>> policies and e-mai...{{dropped:5}}
>>
>> ______________________________________________
>> R-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

 

###
UNIVERSITY OF CAPE TOWN 

This e-mail is subject to the UCT ICT policies and e-mai...{{dropped:5}}

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic