From ripley at stats.ox.ac.uk  Tue Jan 25 11:53:19 2011
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue, 25 Jan 2011 10:53:19 +0000 (GMT)
Subject: [Rd] Missing argument vs. empty argument
In-Reply-To: <4D3E9793.6040309@cbio.uct.ac.za>
References: <4D3E9793.6040309@cbio.uct.ac.za>
Message-ID: <alpine.LFD.2.00.1101251039330.19721@toucan.stats.ox.ac.uk>

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 at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] Missing argument vs. empty argument
Prof Brian Ripley