@ slot extraction

1

Does anyone know what a slot extraction is? I'm trying to follow a script and a part of it is:

data <- data.frame 
names(data)
unique <- unique(data@data$binomial)

Binomial is the column that I need to use in the case of species names. A species in this case may have more than one line in data.frame , so the application of the unique function. But do not understand the @ function. I saw that it is related to a slot extraction, but I did not understand what it means in practice.

    
asked by anonymous 15.03.2018 / 14:49

1 answer

1

There is a class of objects in R called S4 . The contents within an object of type S4 are called slots . Just as $ is used to access columns in a data.frame, you can access the slots of an object of class S4 via the @ operator.

To illustrate, let's create an example class S4 :

setClass("minha_classe_S4", slots = c(x = "numeric", y = "character"))

We create a class called "my_class_S4" which contains two slots , one named x that needs to be numeric and another one of class y that needs to be text. Now let's create an object of this class:

meu_objeto <- new("minha_classe_S4", x = 1:10, y = "texto")

To access the element x of meu_objeto , we use @ :

meu_objeto@x
    
21.04.2018 / 04:19