[R] default arguments and '...' in a function

Antonio.Gasparrini at lshtm.ac.uk Antonio.Gasparrini at lshtm.ac.uk
Wed Dec 1 20:34:04 CET 2010

Dear R-users,
I'm trying to work out a way to set default values for arguments in a function which includes the optional argument '...'.
In practice, I have a 'plot' method for a function which specifies different types of plots. Every different plot should have different default arguments (for example for 'col', 'ylim' etc), plus the argument '...' to leave further optional choices to the user.
My problem is that I need to specify a large number of arguments in the usage (losing clarity), or alternatively leaving to the user the specification of an high number of argument (adding complexity).
An example.
Suppose I want to create a function f with arguments 'a', and '...'.
Two more arguments 'b' and 'c' should be both set to 1 by default if the user don't include them in '...'.
f <- function(a,...) {
  # set b <- 1 if b is not included in '...'
  # set c <- 1 if c is not included in '...'
I found that internally the optional arguments are stored in list(...), but I haven't found a way to manage them, so the final call to somefunction() will include 'b' and 'c' twice if the user have included them in '...', and returns an error.
Does anyone have some suggestion?
Thanks for your time
Antonio Gasparrini
London School of Hygiene & Tropical Medicine
Department of Social and Environmental Health Research
15-17 Tavistock Place, London WC1H 9SH, UK

More information about the R-help mailing list