S3 vs. S4

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

S3 vs. S4

Erin Hodgess
Dear R People:

Could someone direct me to some documentation on the
difference between S3 and S4 classes, please?

For example, why would a person use one as opposed to another?
Maybe pros and cons of each?

Thanks in advance!

R Version 2.2.0 (I'm downloading the new one this afternoon!) Windows.

Happy New Year!


Sincerely,
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: S3 vs. S4

Marc Schwartz (via MN)
On Sun, 2006-01-01 at 13:07 -0600, Erin Hodgess wrote:

> Dear R People:
>
> Could someone direct me to some documentation on the
> difference between S3 and S4 classes, please?
>
> For example, why would a person use one as opposed to another?
> Maybe pros and cons of each?
>
> Thanks in advance!
>
> R Version 2.2.0 (I'm downloading the new one this afternoon!) Windows.
>
> Happy New Year!


Some places to start:

1. Fritz Leisch's "S4 Classes and Methods" from the useR! 2004 meeting:

   http://www.ci.tuwien.ac.at/Conferences/useR-2004/Keynotes/Leisch.pdf


2. Doug Bates' "Converting Packages to S4" in R News 3/1, 2003:

   http://cran.r-project.org/doc/Rnews/Rnews_2003-1.pdf


3. Thomas Lumley's "Programmer's Niche: A Simple Class, in S3 and S4"
   in R News 4/1, 2004:

   http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf




Also, if you do a Google search with the following:

  http://www.google.com/search?q=site:stat.ethz.ch+s3+s4

that will bring up some discussions (248 hits) in the list archives,
mainly in r-devel, some of which will be relevant to your question.



In addition, you might want to look at:

1. John M. Chambers. Programming with Data. Springer, New York, 1998.
   ISBN 0-387-98503-4.  AKA "The Green Book"


2. William N. Venables and Brian D. Ripley. S Programming. Springer,
   2000. ISBN 0-387-98966-8.


HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: S3 vs. S4

Gabor Grothendieck
In reply to this post by Erin Hodgess
On 1/1/06, Erin Hodgess <[hidden email]> wrote:
> Dear R People:
>
> Could someone direct me to some documentation on the
> difference between S3 and S4 classes, please?

Check out:

http://www.maths.lth.se/help/R/S3toS4/

and references there.


>
> For example, why would a person use one as opposed to another?
> Maybe pros and cons of each?
>

S3 is simpler (but still quite powerful) and can have higher
performance. S4 has more functionality including multiple
inheritance and type checking of arguments.

stats4 in the R distribution is an example of an S4 package.
You could also look at the its package which is an S4 package
for irregular time series and zoo which is an S3 package for
the same purpose (although they differ in a number of ways
even apart from the different oo infrastructures).

Bioconductor is a large set of packages that use S4.

> Thanks in advance!
>
> R Version 2.2.0 (I'm downloading the new one this afternoon!) Windows.
>
> Happy New Year!
>
>
> Sincerely,
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: S3 vs. S4

Sean Davis
In reply to this post by Erin Hodgess



On 1/1/06 2:07 PM, "Erin Hodgess" <[hidden email]> wrote:

> Dear R People:
>
> Could someone direct me to some documentation on the
> difference between S3 and S4 classes, please?
>
> For example, why would a person use one as opposed to another?
> Maybe pros and cons of each?

The Bioconductor project has encouraged my use of S4 classes.  S4 allows
creation of data structures that have methods associated with them, so for
data-structure heavy programming, I think S4 might have some advantages, but
I am NOT an expert in the field.

Just one other link that I have found quite useful:

http://www.stat.auckland.ac.nz/S-Workshop/Gentleman/S4Objects.pdf

Sean

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html