[R] Preserving lists in a function

baptiste auguie baptiste.auguie at googlemail.com
Sat Feb 27 15:45:32 CET 2010


Point well taken --- grid::gpar() is also a good example; I'll make
use of your suggestion in my future coding.

Best,

baptiste

On 27 February 2010 15:02, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> On Sat, Feb 27, 2010 at 11:29 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>> Or use modifyList which is in the core of R.
>
>  All these solutions appear to be adding on more and more code with
> less and less semantics. Result: messy code which is harder to read
> and debug.
>
>  It seems that the arguments should have proper constructors with
> meaningful names. A bit like an optimisation function with a control
> argument. What's better:
>
>  o = optimmy(f, control=list(niter=10,ftol=0.01))
>
> or
>
> o = optimmy(f,control=control(niter=10,ftol=0.01))
>
>  here you are explicitly constructing a 'control' object that has the
> options for controlling the optimiser, and it will have its own
> sensible defaults which the user can selectively override. It seems to
> be the correct paradigm for collecting related parameters, and indeed
> is used in lots of R code.
>
>  Done this way you get selectively overridable arguments, a meaningful
> name, readable code, leveraging the built-in defaults system, and the
> possibility of sticking consistency checks in your control() function.
>
>  Tell me where that is not made of pure win?
>
> Barry
>



More information about the R-help mailing list