What does the "@" operator do?

Hello, occasionally I see the @ operator used, for example:

map$idarea <- 1:nrow(map@data)

in Paula Moraga's book Geospatial Health Data: Modeling and Visualization with R-INLA and Shiny.

The R language definition mentions that it exists, but not much more. It seems to be similar to using $? If so, when do you use one versus the other?

The @ operator is used with objects that are defined as S4 objects. S4 objects have "slots" that store their properties and @ is used to access a slot. The @ is indeed much like the $ used to access items in a list. I found the following with a quick web search.

1 Like

Thanks! Classic case of needing to know the right keywords to search.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.