[Rd] Missing argument vs. empty argument

Renaud Gaujoux renaud at mancala.cbio.uct.ac.za
Tue Jan 25 10:27:47 CET 2011


Hi,

is there an easy, robust, and/or recommended way to distinguish a 
missing argument from an empty argument as in:

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}}



More information about the R-devel mailing list