[R] Preserving lists in a function

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sat Feb 27 15:02:08 CET 2010

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))


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?


More information about the R-help mailing list