Module 7 Assignment
Module 7
GitHub repository: https://github.com/christilly/LIS-6371-USF/blob/main/Module7.R
The data I downloaded was the CSV format of the amino acid composition of the Human papillomavirus E1 protein. The amino acid composition the file is based on is shown below.
The CSV file formatting is shown below.
Generic functions can be applied to this data. However, the data would have to be formatted in a way that operations are useful. For instance, I could remove the numbers representing the amino acids and keep the letter of the amino acids with their percentage concentration. This could be put in a data frame, and more in-depth analysis could be done. This would likely involve a function that cleans the data using string operations. Since we have not covered string manipulation in-depth yet, I did this manually by creating data frame E1_clean. I applied generic functions on this data frame including head(), summary(), sum(), and order().
S3
I created an S3 class by assigning classes to the variables in the data frame ID and measurement. ID was assigned "character" and measurement was assigned "numeric" to represent their contents. Then I created a custom print function for the measurement column that prints the summary of the numeric data there.
S4
I created a new data frame for the S4 class to use as a test. I used the setClass() function to create a new class and added slots for the variables, naming them "character" and "numeric" as before. I then created the object E1_S4 by assigning the class and variables. I then made a custom print method by using setMethod() involving a function that prints a description and the contents of the variables in the data frame.
Additional questions
- You can tell what OO system an object is associated with via process of elimination using functions. isS4() is one function which returns true or false based on whether the object is S4 or not. Using str(object) can give the structure of the object, which will include slots if it is S4. class(object) can be used to identify S3 objects, which will not return slots.
- To determine the base type of an object, you can use typeof() to find the internal type, class() for S3 and S4 objects, and is.*() which returns true or false based on if the object is the specified type or not.
- A generic function is a type of general function which can be applied to many objects, and it will behave differently depending on the object. print() is one example of a generic function.
- There are many differences between S3 and S4. S3 is less structured and more flexible while S4 is more structured and less flexible, involving slots. S3 does not have validity testing, while S4 does. For S3, objects are assigned using class() while in S4 objects are assigned using setClass(), new(), and setMethod().
- Examples of S3 and S4 are shown in my GitHub.
Comments
Post a Comment