Module # 7 R Object: S3 vs. S4 assignment
How do you tell what OO system (S3 vs. S4) an object is associated with?
You can check an Objects class using class(object_name) in order to determine if its S3 or S4. If an object has a formal class definition then it is S4. Most base R objects are S3
How do you determine the base type (like integer or list) of an object?
You can use the command typeof() in order to get a readout of what type an object is. For instance class(mtcars) will give you a readout "data.frame" but typeof(mtcars) will give you the base type list.
You can use the command typeof() in order to get a readout of what type an object is. For instance class(mtcars) will give you a readout "data.frame" but typeof(mtcars) will give you the base type list.
What is a generic function?
A generic function is a function that performs differently depending on the class. R actually decides what the function does for you in a process called method dispatch.
methods() will list all the options the function could perform
some examples of generics
print()
summary()
plot()
mean()
head()
tail()
str()
What are the main differences between S3 and S4?
S3 is a simple and informal way of creating classes. It has less strict creation steps and is based on a class. S4 is strictly defined, often using advanced packages over base R. S4 requires you to set the class and methods used.
In your GitHub, create two examples of S3 and S4.
https://github.com/Wrightkov/r-programming-assignments
Comments
Post a Comment