Module# 7: R Object: S3 vs. S4 assignment

A) How do you tell what OO system (S3 vs. S4) an object is associated with?

I generally look at the object reference symbols. If the datasets have $ association then it is of S3 class, whereas, if it has # then it is of S4. Some package and their preloaded datasets have both classes.

B) How do you determine the base type (like integer or list) of an object?

I use str() or class() function on that object to determine its class association. 

C) What is a generic function?

Generic functions are pre-loaded functions that come pre-loaded with every base R compilers. For examples, mean(), data.frame() and so on.

D) What are the main differences between S3 and S4?

S3 is casual and implements a style of OO programming called generic-function OO. S4 works similarly to S3, but is more formal. S4 tends to require more upfront design than S3, and this investment is more likely to pay off on larger projects where greater resources are available.

E) In your GitHub, create two examples of S3 and S4.

Please see the code chunks below, and check out Lines 46-75.

Comments