आप एस 3 और एस 4 कक्षा सम्मेलनों को मिला रहे हैं। is
और extends
एस 4 कक्षाओं के लिए हैं, लेकिन इन तरीकों को लागू करने के तरीके के कारण एस 3 लोगों के साथ यह काम है। inherits
एस 3 कक्षाओं के लिए लिखा गया था और यह पूरी संगतता के साथ एस 4 वस्तुओं के साथ काम करने का इरादा नहीं है।
inherits
प्रभावी रूप से दूसरे तर्क में निर्दिष्ट कक्षा के साथ class(x)
के परिणाम की तुलना करता है। इसलिए
> class(data.frame())
[1] "data.frame"
शामिल नहीं है "list"
कहीं तो विफल रहता है।
भी इस ?inherits
से ध्यान दें:
The analogue of ‘inherits’ for formal classes is ‘is’. The two
functions behave consistently with one exception: S4 classes can
have conditional inheritance, with an explicit test. In this
case, ‘is’ will test the condition, but ‘inherits’ ignores all
conditional superclasses.
एक और भ्रम की स्थिति एक वस्तु के वर्ग और उस वस्तु के कार्यान्वयन के साथ है। हां एक डेटा फ्रेम is.list()
के रूप में एक सूची है, लेकिन आर की एस 3 कक्षा दुनिया में, data.frame()
कक्षा "data.frame"
"list"
नहीं है।
is(data.frame(),'list')
के लिए, अच्छी तरह से यह उस विशिष्ट वर्ग "list"
का नहीं है इसलिए FALSE
। क्या is(data.frame())
?is
Summary of Functions:
‘is’: With two arguments, tests whether ‘object’ can be treated as
from ‘class2’.
With one argument, returns all the super-classes of this
object's class
इसलिए में प्रलेखित है करता is(data.frame())
कक्षाएं कि "data.frame"
वर्ग फैली (एस 4 भावना, नहीं S3 अर्थ में) दिखा रहा है। यह extends('data.frame','list')
व्यवहार को एस 4 दुनिया में बताता है, "data.frame"
वर्ग "list"
कक्षा का विस्तार करता है।
स्रोत
2013-07-22 22:29:55
दिलचस्प जानकारी वाला एक और फ़ंक्शन 'getClass (' data.frame ') है ' – eddi