[R] Google's R Style Guide

Duncan Murdoch murdoch at stats.uwo.ca
Tue Sep 1 12:16:48 CEST 2009


Corrado wrote:
> Thanks Duncan, Spencer,
>
> To clarify, the situation is:
>
> 1) I have no reasons to choose S3 on S4 or vice versa, or any other coding 
> convention
> 2) Our group has not done any OO developing in R and I would be the first, so I 
> can set up the standards
> 3) I am starting from scratch with a new package, so I do not have any code I 
> need to re-use.
> 4) I am an R OO newbie, so whatever I can learn from the beginning what is 
> better and good for me.
>
> So the questions would be two:
>
> 1) What coding style guide should we / I follow? Is the google style guide 
> good, or is there something better / more prescriptive which makes our 
> research group life easier? 
>   

I don't think I can answer that.  I'd recommend planning to spend some 
serious time on the decision, and then go by your personal impression.  
S4 is definitely harder to learn but richer, so don't make the decision 
too quickly.  Take a look at John Chamber's new book, try small projects 
in each style, etc.

> 2) What class type should I use? From what you two say, I should use S3 
> because is easier to use .... what are the disadvantages? Is there an 
> advantages / disadvantages table for S3 and S4 classes?
>   

S3 is much more limited than S4.  It dispatches on just one argument, S4 
can dispatch on several.  S3 allows you to declare things to be of a 
certain class with no checks that anything will actually work; S4 makes 
it easier to be sure that if you say something is of a certain class, it 
really is.  S4 hides more under the hood: if you understand how regular 
R functions work, learning S3 is easy, but there's still a lot to learn 
before you'll be able to use S4 properly.

Duncan Murdoch




More information about the R-help mailing list