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). Mike -- Michael H. Prager Population Dynamics Team NOAA Center for Coastal Habitat and Fisheries Research Beaufort, North Carolina 28516 USA
You can mix ... and other arguments. See, for example, anova.glm. On 5/25/06, Michael Prager <Mike.Prager at noaa.gov> 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). > > Mike > > -- > Michael H. Prager > Population Dynamics Team > NOAA Center for Coastal Habitat and Fisheries Research > Beaufort, North Carolina 28516 USA > > ______________________________________________ > R-help at 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 >
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 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
Brian, You say "See cbind etc". How would I do that? -- View this message in context: http://n4.nabble.com/Variable-number-of-arguments-to-function-tp800843p1590399.html Sent from the R help mailing list archive at Nabble.com.