Skip to content

S3-S4-R5 dictionary

S3 and S4 are different beasts. So are French and English, but we still have French-English dictionaries even though there’s always the possibility of getting lost in translation.

Below is a table with ‘translations’ that I’ve found can be useful. I intend to keep updating this as I come across other useful ‘translations’. Suggestions welcome. Being much stronger with S3, I hope S4 people share their constructive advice.

Consider an (either S3 or S4) object called x (for simplicity I assume that if x is S3 then its also a list). I use cls, cls1, cls2, etc. to denote names of classes. I use gnrc, gnrc1, gnrc2, etc. to denote names of generic functions.

EDIT: Now covering the R5 system as well. This system is based on reference classes.

S3 S4 R5 Notes
‘elements’ ‘slots’ ‘fields’
x$ x@ x$
as.cls(x) as(x, 'cls')
class(x) class(x) x$getRefClass()
names(x) slotNames(class(x)), getSlots(class(x)) x$getRefClass()$fields() OR ls(x)
gnrc.cls getMethod('gnrc', 'cls')
methods('gnrc') showMethods('gnrc') x$getRefClass()$methods() Because S4 methods allow for dispatching on multiple arguments, there are some pretty important differences between S3 and S4 here: The S3 version shows the names of all methods; S4 version shows the acceptable classes for each argument of the method.
methods(class = 'cls') showMethods(classes = 'cls')
class(x) <- setClass setRefClass Because of the differences between the three systems, these are VERY rough translations
7 Comments leave one →
  1. Ben Bolker permalink
    September 15, 2012 12:55 am

    just a reminder. How about the analogue of `methods(class=”lm”)` for example, or the corresponding `methods(“profile”)` ?

  2. May 22, 2013 4:33 pm

    another couple of comments. (1) table formatting is messed up in my browser (Firefox on Ubuntu). (2) It would be *really* handy to show how to debug a class method (e.g. debug(method.class), trace(method,sig=”class”), etc.)

  3. mmaechler permalink
    May 5, 2016 7:37 am

    – In newer versions of R, `methods(.)` shows both S3 and S4 methods for a generic function, ..
    – John Chambers (JMC), the creator of all of these really really did never like the term “R5”.
    to the contrary, he has emphasized that both “S4” and reference classes or “formal” classes as opposed to the informal classes (they have no definition!) in S3.
    Just “reference classes” I think is his term.


  1. Translating between S3 and S4 methods — no nonsense guide for the R *user* « ecology & stats
  2. Showing all S3 and S4 methods associated with a particular class or generic function « ecology & stats
  3. Exploring reference class objects in R « ecology & stats

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: