Just don't do it, surely? (was RE: [R] Retrieve ... argument values)

Tony Plate tplate at blackmesacapital.com
Wed Sep 17 18:07:35 CEST 2003


At Wednesday 11:19 AM 9/17/2003 +0100, Simon Fear wrote:
>There have been various elegant solutions to test for the presence
>of a particular named parameter within a ... argument, such as
>
>if (!is.null(list(...)$ylim))
>if ("ylim" %in% names(list(...)))
>
>I think I'd have to comment these lines pretty clearly if I wanted
>to easily follow the code in 6 months time.
>
>But I'm still not convinced it is ever a good idea to use this
>technique in preference to using explicit named arguments. If
>there is something special about "ylim", why insist that it be
>passed within  "..." in the first place? Surely it's better
>to define the function as function(x,ylim=default,...) within which
>you do your special ylim stuff, then call plot(x, ylim=ylim,...))??
>
>Can anyone come up with a good reason not to follow
>that principle? I think my earlier post may have been
>misconstrued: I'm not saying "never write functions that use ...",
>I'm just saying "never write functions that depend on a particular
>argument being passed via ...".

Several reasons for not following that principle involve proliferation of 
defaults -- if the lower level functions have defaults, then those defaults 
must be repeated at the higher levels.  This is a good reason for not 
following that principle, because it makes software maintenance more 
difficult.  Another reason for not following that principle is that tf you 
have several lower level functions with different default values for an 
argument of the same name, it becomes impossible to get the lower-level 
default behavior.

-- Tony Plate




More information about the R-help mailing list