Sunday, February 25, 2024

Week 7 S3 VS S4 Objects


  1. How do you tell what OO system (S3 vs. S4) an object is associated with?                               In S3, objects are defined by the information already known by the characteristics of the object; a character or numeric are recognized in R for their attributes. S4 relies on the designation determined by a user or creator of the data. setClass() produces circumstances where the classes are harder to change and are set apart at the beginning. In addition, many features pertaining to syntax and etiquette separate these systems. For example, rather than using the argument data.frame$variable to identify a column within a data set, S4 used @ and "slot" to call variables and specific instances of data. 

  2. How do you determine the base type (like integer or list) of an object?                                   Both systems are capable of taking advantage of the class() function to determine the class type of an object. Mode is also a tool that can be used to recognize the base type of objects within R. 

  3. What is a generic function?                                                                                                      A generic function is a simple sequence of code that fulfills a command or task. The methods and route can be different however the purpose and ultimate result is a single goal. 

  4. What are the main differences between S3 and S4?                                                               S3 and S4 have two main differences as listed in the lecture: Firstly, S3 objects have classes and methods identified from the beginning, which are considered more informal and widely used. S4 objects have their classes and methods developed later and take a more formal and spatial methodology. Secondly, the language and protocols for articulating commands are different. Language and syntax provide the most visually distinct differences between the two object programming. 

  5. In your GitHub, create two examples of S3 and S4. Week 7 GitHub

No comments:

Post a Comment

Module #10 Building your own R package

 This assignment was tricky because I have never before considered being able to create my own R-package before and considered it to be more...