New to R language and don't know much about S4 classes. I am trying to solve a question
Q. How would you create a new S4 class and its new method?
Create a laptop class, then create an Apple Macbook Pro object
and define a show function to display its CPU type to demonstrate the process.
I created the class using:
setClass("Laptop", slots=list(name="character", CPU_type ="character"))
cl <- new("Laptop",name="Apple Macbook Pro", CPU_type = "8-core CPU")
cl
# Output
An object of class "Laptop"
Slot "name":
[1] "Apple Macbook Pro"
Slot "CPU_type":
[1] "8-core CPU"
Now, I have 3 concerns.
- Is this S4 class correct?
- I don't know how to define show function that will display the CPU type to demonstrate the process.
- I don't understand what does this
and its new method
means?
Can some one help me out?
Thanks.