title: Overloading subscript operator "["
body: <p>I am trying to overload the subscript operator (<code>"["</code>) for a custom class I've created. I am trying to figure out how to deal with the following issues.</p>
  
  <ul>
  <li>How can you figure out if the operator is on lhs or rhs ? i.e. <code>a[x] = foo</code> vs <code>foo = a[x]</code> </li>
  <li>When subscripting the entire dimension like <code>foo = a[,x]</code> how can I identify the first parameter ?</li>
  <li>When using a[seq(x,y)] it seems to be expanding the entire sequence. Is there an easy way to get the first, step and last values without expanding ? </li>
  </ul>
  
  <p><strong>EDIT:</strong> My first point has received multiple answers. In the process I've figured out the answer to the second one. You can use the "missing" function to figure out which parameters are present.</p>
  
  <p>Here is a sample code:</p>
  
  <pre><code>setMethod("[", signature(x="myClass"),
            function(x, i, j, k, l) {
                if (missing(i)) { i = 0 }
                if (missing(j)) { j = 0 }
                if (missing(k)) { k = 0 }
                if (missing(l)) { l = 0 }
            })
  </code></pre>
  
  <p>I have accepted an answer to this question as point number 3 is of least priority to me.</p>