Get startedGet started for free

What's in a Name?

S3 uses a strict naming convention: all S3 methods have a name of the form generic.class.

The converse is not true: a function can have a name containing a dot without being an S3 method. This is the case with many of the functions that have been around since the early days of the S language. For example, all.equal() (docs) is actually an S3 generic, not a method. (This is an example of how leopard.case can be confusing.)

You can check if a function is an S3 generic by calling is_s3_generic() (docs) from the pryr package. You can also print it (by typing its name in the console), then looking to see if it calls UseMethod().

Similarly, you can check if a function is an S3 method by calling is_s3_method() (docs) from pryr. For example,

library(pryr)
is_s3_generic("t")           # generic transpose function
is_s3_method("t.data.frame") # transpose method for data.frames
is_s3_method("t.test")       # a function for Student's t-tests 

Which statements are true?

  1. is.complex() (docs) is a method of the is generic that acts on complex objects.
  2. seq.Date() (docs) is a method of the seq generic that acts on Date objects.
  3. is.na.data.frame() (docs) is a method of the is.na generic that acts on data.frame objects.
  4. sort() (docs) is a generic function.
  5. order() (docs) is a generic function.

This exercise is part of the course

Object-Oriented Programming with S3 and R6 in R

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise