Understanding code for custom in-place modification function? : <p>I came across this post: <a href="http://r.789695.n4.nabble.com/speeding-up-perception-tp3640920p3646694.html" rel="noreferrer">http://r.789695.n4.nabble.com/speeding-up-perception-tp3640920p3646694.html</a> from Matt Dowle, discussing some early? implementation ideas of the <code>data.table</code> package.</p>

<p>He uses the following code:</p>

<pre><code>x = list(a = 1:10000, b = 1:10000) 
class(x) = "newclass" 
"[&lt;-.newclass" = function(x,i,j,value) x      # i.e. do nothing 
tracemem(x)
x[1, 2] = 42L 
</code></pre>

<p><strong>Specifically I am looking at:</strong></p>

<pre><code>"[&lt;-.newclass" = function(x,i,j,value) x
</code></pre>

<p>I am trying to understand what is done there and how i could use this notation.</p>

<p>It looks to me like:</p>

<ul>
<li>i is the row index</li>
<li>j is column index</li>
<li>value is the value to be assigned</li>
<li>x is the object under consideration</li>
</ul>

<p>My best guess would therefore be that i define a custom function for in place modification (for a given class).</p>

<p><code>[&lt;-.newclass</code>  is in class modification for class newclass.</p>

<p>Understanding what happens:
Usually the following code should return an error:</p>

<pre><code>x = list(a = 1:10000, b = 1:10000) 
x[1, 2] = 42L 
</code></pre>

<p>so i guess the sample code does not have any practical use.</p>

<p><strong>Attempt to use the logic:</strong></p>

<p>A simple non-sense try would be to square the value to be inserted:</p>

<pre><code>x[i, j] &lt;- value^2
</code></pre>

<p>Full try:</p>

<pre><code>&gt; x = matrix(1:9, 3, 3)
&gt; class(x) = "newclass"
&gt; "[&lt;-.newclass" = function(x, i, j, value) x[i, j] &lt;- value^2 # i.e. do something
&gt; x[1, 2] = 9
Error: C stack usage  19923536 is too close to the limit
</code></pre>

<p>This doesnt seem to work.</p>

<p><strong>My question(s):</strong></p>

<pre><code>"[&lt;-.newclass" = function(x,i,j,value) x 
</code></pre>

<p>How exactly does this notation work and how would I use it?</p>

<p>(I add data.table tag since the linked discussion is about the "by-reference" in place modification in data.table, i think).</p>
