[R] R Style Guide -- Was Post-hoc tests in MASS using glm.nb

Martin Maechler maechler at stat.math.ethz.ch
Thu May 19 12:26:03 CEST 2011


    BertG> Thanks Bill. Do you and others think that a link to
    BertG> this guide (or another)should be included in the
    BertG> Posting Guide and/or R FAQ?

Hmm, that guide is Google's work, and is probably quite good if
you have a group of R programmers in the same company,
but e.g., has not been published in collaboration with the R core team, 
and actually somewhat differs from our own .. much less formal
and not officially laid down styles 
{yes: "s".. but we still have a few parts we agree on...}

2nd problem with any style guide: "Base R" already comes
with several thousand of functions, classes and other objects, which
have grown from more than 20 years of S, S+ and then R history,
and most things cannot feasibly be changed now (or could, say 5
years ago), for back compatibility reasons.

Further,... more philosophically:
For many of us, programming (R or otherwise) is considered
a creative activity to quite some extent, and creativity can be
crushed by too rigid rules.  I'd state that cultural history
shows that human culture implicitly follows many rules, but it
is (almost) only interesting because the are enough exceptions
to those rules.

Martin Maechler  
       @ ETH Zurich and R Core Team since its inception
       but speaking entirely for myself ..


    BertG> On Tue, May 17, 2011 at 4:07 PM,
    BertG> <Bill.Venables at csiro.au> wrote:
    >> Amen to all of that, Bert.  Nicely put.  The google style
    >> guide (not perfect, but a thoughtful contribution on
    >> these kinds of issues, has avoiding attach() as its very
    >> first line.  See
    >> http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html)
    >> 
    >> I would add, though, that not enough people seem yet to
    >> be aware of within(...), a companion of with(...) in a
    >> way, but used for modifying data frames or other kinds of
    >> list objects.  It should be seen as a more flexible
    >> replacement for transform() (well, almost).
    >> 
    >> The difference between with() and within() is as follows:
    >> 
    >> with(data, expr, ...)
    >> 
    >> allows you to evaluate 'expr' with 'data' providing the
    >> primary source for variables, and returns *the evaluated
    >> expression* as the result.  By contrast
    >> 
    >> within(data, expr, ...)
    >> 
    >> again uses 'data' as the primary source for variables
    >> when evaluating 'expr', but now 'expr' is used to modify
    >> the varibles in 'data' and returns *the modified data
    >> set* as the result.

    [ .... very nice reasoning and example add why 
         people should use  within()  in many cases ... ]



More information about the R-help mailing list