[Rd] advice on arguments

Duncan Murdoch murdoch at stats.uwo.ca
Thu Jun 29 19:08:13 CEST 2006


On 6/29/2006 12:53 PM, Ben Bolker wrote:
>     I have a general style question about R coding.
> 
>    Suppose I'm writing a function (foo1) that calls other functions
> (foo2, foo3, ...) which have complicated argument
> lists (e.g. optim(), plot()), _and_
> I may be calling several different functions in the body of
> foo1.  Since foo2 and foo3 have different sets of arguments, I
> can't just use "..." ; I did write some code a while ago that
> would look at formals() to dissect out arguments that should
> be passed to the different functions, but it seemed overly
> complex.
> 
>   The particular case I have now is a little simpler.
> 
>   foo2 (points3d) and foo3 (spheres3d)
> are both functions from the rgl package
> that pass arguments such as color, alpha, etc. along to
> an rgl.material() command with lots of possible arguments.
> (The function may also call segments3d or lines3d, but
> these all have the same arguments as points3d.)
> However, to change the size of points you use "size"; to
> change the size of spheres you use "radius".  Do I
> (1) add "radius" to the argument list, cluttering up
> the argument list for one particular special case?
> (2) add "size" to the argument list, so that it doesn't
> become part of "..." and I can say spheres3d(radius=size,...) ?
> (3) do something like
>     dotlist = list(...)
>     if (type=="s" && !is.null(dotlist$size)) radius <- dotlist$size
> and pull "size" out of ... myself (and make a note to that
> effect in  the documentation)?
>   (I guess another general solution to this is to ask for
> lists of arguments, like MoreArgs in mapply(). Another
> would be to go back and change spheres3d to make size
> a synonym for radius ... )

I would do (2) in general, but in this particular case it might not be 
right.  "size" is measured in pixels, and "radius" is measured in data 
units, so they really are different things.  You could try to fiddle it 
so the radius is set to the right number of units to match the number of 
pixels that were requested, but users can change the scale pretty easily.

Duncan Murdoch



More information about the R-devel mailing list