[R] Google's R Style Guide

Duncan Murdoch murdoch at stats.uwo.ca
Sat Aug 29 22:28:11 CEST 2009


On 29/08/2009 12:03 PM, Corrado wrote:
> I do not understand why one should use a S3 preferentially on a S4 class, if 
> S4 is more rigorous.

As Spencer said, most people use either one or the other.  I think it's 
generally a bad idea to mix them (there are strange semantics if you do 
that), so using just one is a good idea.

Which do you use?  If you're a programmer working in a group, whatever 
the rest of the group uses.  It appears from the style guide that at 
Google that's S3.  That would be my choice too, but there are lots of 
people who are very successful with S4.

Now I'm tempted to try to guess what character traits would make someone 
prefer S4, but I think I'd only get into trouble ;-).

Duncan Murdoch

> 
> (The premiss is I am a newbie with OO programming in R, and would like to 
> understand what is the "proper" way to OO program in R ....)
> 
> Regards
> 
> 
> 
> On Saturday 29 August 2009 16:23:39 hadley wickham wrote:
>>>> An opening curly brace should never go on its own line;
>>> I tend to do this:
>>>
>>> f <- function()
>>> {
>>>  if (TRUE)
>>>    {
>>>      cat("TRUE!!\n")
>>>    } else {
>>>      cat("FALSE!!\n")
>>>    }
>>> }
>>>
>>> (I don't usually put one-liners in if/else blocks; here I would have
>>> used ifelse)
>>>
>>> I haven't seen many others format code in this way. Is there an
>>> objective reason for this (such as the rule for the trailing "}") or
>>> is this just aesthetics?
>> It's probably just aesthetics.  I don't like it because it increases
>> the number of lines without much real benefit - indenting already
>> gives you all the hints you need.
>>
>> Hadley
> 
> 
>




More information about the R-help mailing list