title: Why does data.table change order of the columns?
body: <p>I encountered the following puzzling (for me) behavior of the <code>data.table</code> when combining <code>get</code> in J with <code>.SDcols</code>: columns order is not preserved, as in:</p>
  
  <pre><code>mtcarsDT &lt;- setDT(copy(mtcars))
  vars &lt;- c( "disp", "hp", "mpg")
  fun &lt;- "median"
  mtcarsDT[, lapply(.SD, median), .SDcols = vars]
  #     disp  hp  mpg
  # 1: 196.3 123 19.2
  mtcarsDT[, lapply(.SD, get(fun)), .SDcols = vars] 
  #     mpg  disp  hp
  # 1: 19.2 196.3 123
  </code></pre>
  
  <p>Note that this doesn't happen without <code>.SDcols</code>:</p>
  
  <pre><code>mtcarsDT[, lapply(.SD, median)]
  #     mpg cyl  disp  hp  drat    wt  qsec vs am gear carb
  # 1: 19.2   6 196.3 123 3.695 3.325 17.71  0  0    4    2
  mtcarsDT[, lapply(.SD, get(fun))] 
  #     mpg cyl  disp  hp  drat    wt  qsec vs am gear carb
  # 1: 19.2   6 196.3 123 3.695 3.325 17.71  0  0    4    2
  </code></pre>
  
  <p>I am wondering if anyone can shed light on that behavior: is it a bug or a feature? In the latter case how can I deduce the order that columns will appear? </p>
  
  <p>Ultimately I want to name the new columns according to original variable names with a call like:</p>
  
  <pre><code>newVars &lt;- paste0(vars, "_median")
  mtcarsDT[, (newVars) := lapply(.SD, get(fun)), .SDcols = vars]
  </code></pre>
  
  <p>which now produces incorrect results.</p>