title: What is the difference between extraction via $ and @ in R?
body: <p>I wonder what is the difference between the "component/slot extraction" (via <code>?Syntax</code>) operators <code>$</code> (dollar sign) and <code>@</code> (at symbol) in R. </p>
  
  <p>Here's an example with <code>$</code>: </p>
  
  <pre><code>yo=data.frame(c(1:10), c(rnorm(10,0,1)))
  yo$c.1.10.
  </code></pre>
  
  <p>prints: </p>
  
  <pre><code> [1]  1  2  3  4  5  6  7  8  9 10
  </code></pre>
  
  <p> </p>
  
  <pre><code>yo@c.1.10.
  Error: trying to get slot "c.1.10." from an object (class "data.frame") that is not an S4 object 
  </code></pre>
  
  <p>Here's an example with <code>@</code>: </p>
  
  <pre><code>setClass("track", representation(x="numeric", y="numeric"))
  myTrack &lt;- new("track", x = -4:4, y = exp(-4:4))
  myTrack@x
  </code></pre>
  
  <p>prints: </p>
  
  <pre><code>[1] -4 -3 -2 -1  0  1  2  3  4
  </code></pre>
  
  <p> </p>
  
  <pre><code>myTrack$x
  Error in myTrack$x : $ operator not defined for this S4 class
  </code></pre>
  
  <p>In either case, why does one work and not the other?</p>
  
  <p>Another example is the following from the <code>SoDA</code> package in R, in the function <code>geoXY</code>: </p>
  
  <pre><code>library(SoDA)
  xy &lt;- geoXY(gpsObject1@latitude, gpsObject1@longitude, unit = 1000)
  plot(xy[,1], xy[,2], asp = 1)
  </code></pre>