स्लॉट एस 4 वस्तुओं से जुड़ी हैं। एक स्लॉट को किसी ऑब्जेक्ट के भाग, तत्व या "संपत्ति" के रूप में देखा जा सकता है। मान लें कि आपके पास कार ऑब्जेक्ट है, तो आपके पास स्लॉट "कीमत", "दरवाजे की संख्या", "इंजन का प्रकार", "माइलेज" हो सकता है।
आंतरिक रूप से, यह एक सूची का प्रतिनिधित्व किया जाता है। एक उदाहरण:
setClass("Car",representation=representation(
price = "numeric",
numberDoors="numeric",
typeEngine="character",
mileage="numeric"
))
aCar <- new("Car",price=20000,numberDoors=4,typeEngine="V6",mileage=143)
> aCar
An object of class "Car"
Slot "price":
[1] 20000
Slot "numberDoors":
[1] 4
Slot "typeEngine":
[1] "V6"
Slot "mileage":
[1] 143
यहाँ, मूल्य, numberDoors, typeEngine और लाभ एस 4 वर्ग "कार" के स्लॉट हैं। यह एक मामूली उदाहरण है, वास्तविकता स्लॉट में खुद को जटिल वस्तुएं फिर से हो सकती हैं।
स्लॉट कई मायनों में पहुँचा जा सकता है:
> [email protected]
[1] 20000
> slot(aCar,"typeEngine")
[1] "V6"
या एक विशिष्ट विधि के निर्माण के माध्यम से (अतिरिक्त दस्तावेज़ देखें)।
एस 4 प्रोग्रामिंग पर अधिक जानकारी के लिए this question देखते हैं। यदि अवधारणा अभी भी आपके लिए अस्पष्ट लगती है, तो ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग में एक सामान्य परिचय मदद कर सकता है।
पुनश्च: dataframes और सूचियों, जहाँ आप $
का उपयोग नामित चरों/तत्वों का उपयोग करने के साथ अंतर ध्यान रहे।
Slots:
The data contained in an object from an S4 class is defined
by the _slots_ in the class definition.
Each slot in an object is a component of the object; like
components (that is, elements) of a list, these may be
extracted and set, using the function ‘slot()’ or more often
the operator ‘"@"’. However, they differ from list
components in important ways. First, slots can only be
referred to by name, not by position, and there is no partial
matching of names as with list elements.
....
'स्लॉट पर मदद से है कि()' समारोह - यह दस्तावेज़ कराना नहीं है, क्या एक स्लॉट उन्हें कितना उपयोग करने के लिए, है। –