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@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.
______________________________________________
R-help@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.