[R] Google's R Style Guide

spencerg spencer.graves at prodsyse.com
Sat Aug 29 18:47:13 CEST 2009


      S3 is very easy to change;  S4 is very difficult.  This provides 
advantages and disadvantages for both.  Some people swear by one and 
curse the other -- from both sides. 


      S4 is newer, and I have had problems in the past finding out what 
S4 methods are available and finding acceptable documentation more 
generally.  The "methods" function quickly identifies all installed S3 
methods for an object of a particular class and all classes for which a 
given generic function has S3 methods.  The help page for "methods" now 
says, "See Also: ... For S4, 'showMethods', 'Methods'."  I very much 
appreciate the work of whomever added this "See Also", because the next 
time I want to find S4 methods, it will make it easier for me to do so.  
Chambers (1998) Programming with Data (Springer) described many things 
that did not work in any version of S to which I've had access.  
Chambers (2008) Software for Data Analysis (Springer) is better but 
still includes many things that I could not get to work without writing 
the author. 


      I use S3 routinely, and I've tried multiple times to learn more 
about S4 methods without yet achieving a critical mass that would allow 
me to use them.  S-Plus and R have been my primary tool for well over 15 
years. 


      Hope this helps.
      Spencer


Corrado wrote:
> I do not understand why one should use a S3 preferentially on a S4 class, if 
> S4 is more rigorous.
>
> (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
>>     
>
>
>
>   


-- 
Spencer Graves, PE, PhD
President and Chief Operating Officer
Structure Inspection and Monitoring, Inc.
751 Emerson Ct.
San José, CA 95126
ph:  408-655-4567




More information about the R-help mailing list