[R] Retrieve ... argument values

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Sep 16 16:48:38 CEST 2003


huan.huang at bnpparibas.com writes:

> Dear R users,
> 
> I want to retrieve "..." argument values within a function. Here is a small
> exmaple:
> 
> myfunc <- function(x, ...)
> {
>       if (hasArg(ylim))  a <- ylim
>       plot(x, ...)
> }
> 
> x <- rnorm(100)
> myfunc(x, ylim=c(-0.5, 0.5))
> Error in myfunc(x, ylim = c(-0.5, 0.5)) : Object "ylim" not found
> >
> 
> I need to retrieve values of "ylim" (if it is defined when function
> is called) for later use in the function. Can anybody give me some
> hint?

Yes, several:

"ylim" %in% names(match.call(expand.dots=FALSE)$...)

or

"ylim" %in% names(list(...)

(Use the former if it is somehow important not to evaluate the
arguments).

Or even

a <- list(...)$ylim

and then check for is.null(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