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 '...'
  somefunction(a,b,c,...)
}
 
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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to