Re: [R] Variable number of arguments to function

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 26 May 2006 - 03:36:59 EST

On Thu, 25 May 2006, Michael Prager wrote:

> Dear R List,
>
> I have used ... to pass a varying number of arguments to a function.
> The function takes parts of specialized data objects (they happen to be
> lists) and makes comparative graphs and analyses. The code shell looks
> like this:
>
> models.compare <- function(...) {
> ## Get the data objects passed
> models <- list(...)
> nmodels <- length(models)
> ## Get names of models:
> modelnames <- as.character(substitute(c(...))[-1])
> ##### much code omitted here #####
> }
>
>
> Now I would like to pass a few named arguments to the function as well,
> to control how it prints, plots, makes files. I am seeking advice on
> the simplest way to do this (along with the varying number of data
> arguments).

Add them after ... to the argument list and always specify the full argument name when calling models.compare.

For R examples see .C, cbind, max, sum ....

-- 
Brian D. Ripley,                  ripley@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri May 26 03:39:53 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 26 May 2006 - 04:10:22 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.