Does anyone know what a slot is in R?
I did not find the explanation of its meaning. I get a recursive definition: "Slot function returns or set information about the individual slots of an objects"
Help would be appreciated, Thanks - Alley
Does anyone know what a slot is in R?
I did not find the explanation of its meaning. I get a recursive definition: "Slot function returns or set information about the individual slots of an objects"
Help would be appreciated, Thanks - Alley
Slots are linked to S4 objects. A slot can be seen as a part, element or a "property" of an object. Say you have a car object, then you can have the slots "price", "number of doors", "type of engine", "mileage".
Internally, that is represented a list. An example :
Here, price, numberDoors, typeEngine and mileage are slots of the S4 class "Car". This is a trivial example, in reality slots themselves can be again complex objects.
Slots can be accessed in numerous ways :
or through the construction of a specific method (see extra documentation).
For more on S4 programming see this question. If the concept still sounds vague to you, a general introduction in Object Oriented Programming could help.
PS: Mind the difference with dataframes and lists, where you use
$
to access named variables/elements.In addition to the resources @Joris points you to, plus his own answer, try reading
?Classes
, which includes the following on slots:Just as
names(variable)
lists up all the$
-accessible names of a complex variable, so tooslotNames(object)
lists all the slots of an object.Very handy to discover what goodies your fit-object contains for your viewing pleasure.
No idea why R has to redefine everything. Most normal programming languages call them "properties" or "attributes".