title: Data frame slicing with dynamic column name as variable
body: <p>Consider the data data table</p>
  
  <pre><code>DT1 = as.data.table(data.frame(col1 = c(1,2,3,2,5,1,3,3,1,2), col2 = c(3,4,5,4,3,4,5,3,4,5), col3 = c(1,2,3,4,5,6,7,8,9,10)))
  </code></pre>
  
  <p>I would like to column-slice it from variable.</p>
  
  <p>So</p>
  
  <pre><code>DT1[, c("col1", "col3")]
  </code></pre>
  
  <p>will work with no problem.
  How about slicing from column names stored in variables.</p>
  
  <pre><code>col_name1 &lt;- "col1"
  col_name2 &lt;- "col3"
  </code></pre>
  
  <p>I have tried <code>get</code> but with no luck. </p>
  
  <pre><code>DT1[, c(get(col_name1), "col2")]
  &gt;[1] "1"    "2"    "3"    "2"    "5"    "1"    "3"    "3"    "1"    "2"    "col2"
  DT1[, get(c(col_name1, "col2"))]
  &gt;[1] 1 2 3 2 5 1 3 3 1 2
  
  
  DT1[, get(c(col_name1, col_name2))]
   &gt;[1] 1 2 3 2 5 1 3 3 1 2
  DT1[, c(get(col_name1), get(col_name2))]
   &gt;[1]  1  2  3  2  5  1  3  3  1  2  1  2  3  4  5  6  7  8  9 10
  </code></pre>
  
  <p>Any idea ? While we are at it, could you also help me explain the logic behind the unsuccessful approaches that I tried ? Thank you.</p>