title: Removing multiple columns from R data.table with parameter for columns to remove
body: <p>I'm trying to manipulate a number of data.tables in similar ways, and would like to write a function to accomplish this.  I would like to pass in a parameter containing a list of columns that would have the operations performed.  This works fine when the vector declaration of columns is the left hand side of the := operator, but not if it is declared earlier (or passed into the function).  The follow code shows the issue.</p>
  
  <pre><code>dt = data.table(a = letters, b = 1:2, c=1:13)
  colsToDelete = c('b', 'c')
  dt[,colsToDelete := NULL] # doesn't work but I don't understand why not.
  dt[,c('b', 'c') := NULL] # works fine, but doesn't allow passing in of columns
  </code></pre>
  
  <p>The error is "Adding new column 'colsToDelete' then assigning NULL (deleting it)."  So clearly, it's interpreting 'colsToDelete' as a new column name.</p>
  
  <p>The same issue occurs when doing something along these lines</p>
  
  <pre><code>dt[, colNames := lapply(.SD, adjustValue, y=factor), .SDcols = colNames]
  </code></pre>
  
  <p>I new to R, but rather more experienced with some other languages, so this may be a silly question.</p>