Perhaps most of you have already seen this? http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html Comments/Critiques? Thanks, Esmail ps: Reminds me of PEP 8 for Python http://www.python.org/dev/peps/pep-0008/ Maybe not that surprising since Python is also one of the main languages used by Google.
On 8/28/2009 8:59 AM, Esmail wrote:> Perhaps most of you have already seen this? > > http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html > > Comments/Critiques?The rules are mostly reasonable, though they aren't the ones followed in the R source. One bad rule is the one on curly braces: An opening curly brace should never go on its own line; a closing curly brace should always go on its own line. The problem is the second part. If the closing brace is followed by an else clause, the else should go on the same line as the brace, or things will parse differently when pasted than they do in a function. For example, this follows their style to the letter: f <- function() { if (TRUE) { cat("TRUE!!\n") } else { cat("FALSE!!\n") } } and it works as intended, but if you cut and paste the lines in the body (starting with "if (TRUE)"), the else clause will be a syntax error. If it had been formatted as f <- function() { if (TRUE) { cat("TRUE!!\n") } else { cat("FALSE!!\n") } } it would work even when cut and pasted. Duncan Murdoch> > Thanks, > Esmail > > ps: Reminds me of PEP 8 for Python > > http://www.python.org/dev/peps/pep-0008/ > > Maybe not that surprising since Python is also one of the main languages > used by Google. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On 28-Aug-09 12:59:24, Esmail wrote:> Perhaps most of you have already seen this? > > http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html > > Comments/Critiques? > > Thanks, > Esmail > > ps: Reminds me of PEP 8 for Python > > http://www.python.org/dev/peps/pep-0008/ > > Maybe not that surprising since Python is also one of the main > languages used by Google.I think it is grossly over-prescriptive. For example: "function names have initial capital letters and no dots" is violated throughout R itself. Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 28-Aug-09 Time: 14:21:58 ------------------------------ XFMail ------------------------------
Esmail wrote:> Perhaps most of you have already seen this? > > http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html > > Comments/Critiques?The recommendation of variable.name over variable_name or variableName is contentious (to say the least) because of the clash with S3 method conventions. The ESS convention of single, double and triple # comments needs at least to be mentioned. Otherwise, unsuspecting programmers will be driven up the wall when coding or editing in Emacs.> > Thanks, > Esmail > > ps: Reminds me of PEP 8 for Python > > http://www.python.org/dev/peps/pep-0008/ > > Maybe not that surprising since Python is also one of the main > languages > used by Google. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Esmail, Very nice; thanks! Tom ----- Original Message ----- From: Esmail <esmail.js at gmail.com> Date: Friday, August 28, 2009 8:59 am Subject: [R] Google's R Style Guide> Perhaps most of you have already seen this? > > http://google-styleguide.googlecode.com/svn/trunk/google-r- > style.html > Comments/Critiques? > > Thanks, > Esmail > > ps: Reminds me of PEP 8 for Python > > http://www.python.org/dev/peps/pep-0008/ > > Maybe not that surprising since Python is also one of the main > languages used by Google. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.htmland provide commented, minimal, self-contained, > reproducible code. >
> Perhaps most of you have already seen this? > > ?http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html > > Comments/Critiques?I made my own version that reflects my personal biases: http://had.co.nz/stat405/resources/r-style-guide.html Hadley -- http://had.co.nz/
A few thoughts: -- As for naming preferences, in an interactive R session or answering an R-help question I'm glad I can type lm(log(y) ~ atan(x)) rather than FitLinearModel(CalculateNaturalLogarithm(y) ~ CalculateInverseTangent(x)) -- For consistency, their function makeColName(...) should be MakeColName(...) -- I was happy to see promotion of "<-". Reading code using '=' for both object assignment and argument setting is a little like fingernails on a blackboard...again and again and... -- It's nice that people have made these guides available Kingsford Jones On Fri, Aug 28, 2009 at 6:59 AM, Esmail<esmail.js at gmail.com> wrote:> Perhaps most of you have already seen this? > > ?http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html > > Comments/Critiques? > > Thanks, > Esmail > > ps: Reminds me of PEP 8 for Python > > ? ?http://www.python.org/dev/peps/pep-0008/ > > ? ?Maybe not that surprising since Python is also one of the main languages > ? ?used by Google. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >