Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: what are Slots?

Tags:

oop

r

r-faq

s4

slot

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

like image 607
user573347 Avatar asked Jan 17 '11 13:01

user573347


People also ask

What is slot in R programming?

The slot machine is a game, and it comprises two steps: Generating three symbols randomly from 7 symbols and For the generated three symbols, computing score.

What is a slot in programming?

3. A slot is a computer processor connection designed to make upgrading the processor easier, where the user would only have to slide a processor into a slot.

What is the function of slot?

In computers, a slot, or expansion slot , is an engineered technique for adding capability to a computer in the form of connection pinholes (typically, in the range of 16 to 64 closely-spaced holes) and a place to fit an expansion card containing the circuitry that provides some specialized capability, such as video ...

What is Setclass?

A set class is a group of pitch-class sets related by transposition or inversion. Set classes are named by their prime form : the version of the set that is transposed to zero and is most compact to the left (compared with its inversion).


1 Answers

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 :

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 

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 :

> aCar@price [1] 20000 > slot(aCar,"typeEngine") [1] "V6"     

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.

like image 179
Joris Meys Avatar answered Sep 20 '22 23:09

Joris Meys