40

As I'm often confronted with situations where S4 programming is needed to keep an overview, I've collected quite some sources on S4 objects, methods and programming. I've listed them here as a reference. Please add your own sources as well.

On the web

  • The methods help files : help files from the package methods, where much of the necessary information can be found
  • S4 classes in 15 pages : Short introduction on the programming with S4 objects.
  • How S4 methods work : more explanation about the underlying mechanisms.
  • Not so short introduction to S4 : with practical examples of how to construct the classes and some useful tips. It contains a handy overview as appendix, but contains errors as well. Care should be taken using this one.
  • OOP in R : handout notes with practical examples on S3 and S4
  • S4 Objects : presentation by Thomas Lumley about S4 objects.
  • R object oriented programming : in-depth introduction to object oriented programming in R. It covers S3, S4 and S4 reference classes. The accompanying sequences package implements the class system used throughout the slides.

Books

  • Software for Data Analysis-Programming with R (J. Chambers) : A classic, although not reviewed positive everywhere, that contains a large section on S4
  • R programming for Bioinformatics (R. Gentleman) : specifically directed towards working with Bioconductor, which is completely based on S4. But it gives a broad overview and is useful for many other people too.

PS : if somebody finds the community checkbox, you can make this a community-owned post. Somehow I can't find it in the edit window any more...

Tungurahua
  • 489
  • 7
  • 21
Joris Meys
  • 106,551
  • 31
  • 221
  • 263
  • How about adding the links to help topics in methods package directly? There are just a few of them, and is useful for quick reference. By the way "Not so short introduction to s4" has a memo at the end which is worth pointing out in my opinion. I am ussing it as refcard. – VitoshKa Nov 10 '10 at 10:52
  • Community wiki is now available to user with [at least 10.000 reputation](http://meta.stackexchange.com/questions/11740/what-are-community-wiki-posts/11741#11741). So ask Dirk or Shane on chat ;) – Marek Nov 10 '10 at 12:10
  • 2
    I would not recommend the "not so short introduction to S4" - it unfortunately contains a large number of errors. – hadley Nov 10 '10 at 13:47
  • @Marek: If enough of us edit it it will also become community wiki automatically. – Ari B. Friedman Jul 20 '11 at 09:45

3 Answers3

27

My write up of S4 (still in progress) is available here: http://adv-r.had.co.nz/S4.html

ctbrown
  • 2,271
  • 17
  • 24
hadley
  • 102,019
  • 32
  • 183
  • 245
4

R for programmers (Matloff) (free) and Introduction to scientific programming and simulation (Jones) have a short section on "new-style" S4 classes.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
2

Another good book by John Chambers: "Programming with Data: A Guide to the S Language". As the name suggests it is actually about S, not R, but it provides a lot of valuable information about S4 classes anyway.

There's also some information in the R manuals "Writing R Extensions" and "R Internals" (particularly the latter). Those can be found at http://cran.r-project.org/doc/manuals/.

Finally, I would recommend "How S4 Methods Work", which is a great overview of how to think about S4 as it fits into R.

Eli Sander
  • 1,228
  • 1
  • 13
  • 29