[R] take precisely one named argument

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Dec 17 15:26:37 CET 2004


"BXC (Bendix Carstensen)" <bxc at steno.dk> writes:

> specify:
> 
> f <- function(...,a=NULL,b=NULL) {...etc

Or (variant of same)

f <- function(..., a, b) {
    if (nargs() != 1 || length(list(...)))
          stop("precisely one of a=x or b=y must be given")
    else
          if (missing(a)) 2*b else a
}


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list