1

I would like to know about functionality of "@" (at sign) in R.
Let's say:
In the example below if I call perf1@x.values it starts to show all x.values. but I cann't access to second value of x.values by calling perf@x.values[2] !

> str(perf1)
Formal class 'performance' [package "ROCR"] with 6 slots
  ..@ x.name      : chr "False positive rate"
  ..@ y.name      : chr "True positive rate"
  ..@ alpha.name  : chr "Cutoff"
  ..@ x.values    :List of 1
  .. ..$ : num [1:3966] 0 0.0005 0.001 0.0015 0.0015 0.002 0.0025 0.0025 0.003 0.0035 ...
  ..@ y.values    :List of 1
  .. ..$ : num [1:3966] 0e+00 0e+00 0e+00 0e+00 5e-04 5e-04 5e-04 1e-03 1e-03 1e-03 ...
  ..@ alpha.values:List of 1
  .. ..$ : num [1:3966] Inf 0.996 0.993 0.986 0.98 ...

I wonder what is usage of "@" sign in R?
and how can I call certain values by using @ sign?
thanks

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
Cina
  • 9,759
  • 4
  • 20
  • 36

1 Answers1

7

S4 objects are lists with nodes or leaves (which are technically calls 'slots') that are accessible with the @ operator just as S3 objects are accessed with $.

Take a look at:

str( perf1@x.name )
str( perf1@y.name )

Notice that these may contain ordinary S3 lists as with:

str( perf1 @ x.values) # a list
str( perf1 @ x.values[[1]] ) # a numeric vector
perf1 @ x.values[[1]][1]   # the first value in `x.values`

It's considered poor form to do this, since the authors of S4 objects are supposed to equip you with accessor functions that allow you to get anything that would be useful.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • That wasn't my edit. I only added links to documentation. Since it took me a while to find the relevant pages (S4 documentation is rather scattered around), I thought that would be useful. – Richie Cotton Feb 18 '15 at 07:27
  • OK, looking at the revisions, apparently it was my edit. I did drop a croissant on my keyboard while I was updating your question, so it's either that or my fat fingers that caused the typo. – Richie Cotton Feb 18 '15 at 07:29
  • OK. Thanks for the other edits. Does make answer more useful. – IRTFM Feb 18 '15 at 07:50