Skip to content
Prev 191668 / 398498 Next

Google's R Style Guide

On 8/28/2009 8:59 AM, Esmail wrote:
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

Thread (50 messages)

Esmail Google's R Style Guide Aug 28 Duncan Murdoch Google's R Style Guide Aug 28 (Ted Harding) Google's R Style Guide Aug 28 Peter Dalgaard Google's R Style Guide Aug 28 Duncan Murdoch Google's R Style Guide Aug 28 Thomas Adams Google's R Style Guide Aug 28 Kevin Wright Google's R Style Guide Aug 28 Hadley Wickham Google's R Style Guide Aug 28 Duncan Murdoch Google's R Style Guide Aug 28 Barry Rowlingson Google's R Style Guide Aug 28 Hadley Wickham Google's R Style Guide Aug 28 John Sorkin Google's R Style Guide Aug 28 Kevin Wright Google's R Style Guide Aug 28 Hadley Wickham Google's R Style Guide Aug 28 Henrik Bengtsson Google's R Style Guide Aug 28 Hadley Wickham Google's R Style Guide Aug 28 Hadley Wickham Google's R Style Guide Aug 28 Kevin Wright Google's R Style Guide Aug 28 Erich Neuwirth Google's R Style Guide Aug 28 Duncan Murdoch Google's R Style Guide Aug 28 Kevin Wright Google's R Style Guide Aug 28 Henrik Bengtsson Google's R Style Guide Aug 28 Barry Rowlingson Google's R Style Guide Aug 28 Deepayan Sarkar Google's R Style Guide Aug 28 Duncan Murdoch Google's R Style Guide Aug 28 Kingsford Jones Google's R Style Guide Aug 28 Esmail Google's R Style Guide Aug 29 Esmail Google's R Style Guide Aug 29 Esmail Google's R Style Guide Aug 29 Esmail Google's R Style Guide Aug 29 Max Kuhn Google's R Style Guide Aug 29 Hadley Wickham Google's R Style Guide Aug 29 Uwe Ligges Google's R Style Guide Aug 29 Corrado Topi Google's R Style Guide Aug 29 Philippe GROSJEAN Google's R Style Guide Aug 29 Spencer Graves Google's R Style Guide Aug 29 diegol Google's R Style Guide Aug 29 (Ted Harding) Google's R Style Guide Aug 29 Duncan Murdoch Google's R Style Guide Aug 29 John Sorkin Google's R Style Guide Aug 29 Hadley Wickham Google's R Style Guide Aug 29 Duncan Murdoch Google's R Style Guide Aug 29 Esmail Google's R Style Guide Aug 30 David Scott Google's R Style Guide Aug 31 Baptiste Auguie Google's R Style Guide Aug 31 Romain Francois Google's R Style Guide Aug 31 Duncan Murdoch Google's R Style Guide Aug 31 Baptiste Auguie Google's R Style Guide Aug 31 Vitalie S. Google's R Style Guide Aug 31 Tobias Verbeke Google's R Style Guide Aug 31