title: data.table assignment by reference within function
body: <p>I have a (big-ish) <code>data.table</code>. And I want to do the same thing to many of its columns. Say,</p>
  
  <pre><code>dt &lt;- data.table( ltr = letters[1:5] )
  func &lt;- function( dt ){
      cols &lt;- colnames( dt ) # Columns to apply op to
      dt[ , (cols) := lapply( .SD, toupper ), .SDcols = cols ]
      return( dt )
  }
  </code></pre>
  
  <p>The function <code>func</code> converts characters to upper case for all columns. I try</p>
  
  <pre><code>func( dt )
  </code></pre>
  
  <p>I get the error</p>
  
  <pre><code>Error in `:=`((cols), lapply(.SD, toupper)) : 
  Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=").
  </code></pre>
  
  <p>I'm still not sure what causes the error and have read <code>help(":=")</code>, the FAQs and some other (SO) sources. Any help?</p>
  
  <p><strong>NOTE: I should have given more details about the context. <code>func</code> is a function written in a package. That makes all the difference</strong></p>