title: When should I use setDT() instead of data.table() to create a data.table?
body: <p>I am having difficulty grasping the essence of the <code>setDT()</code> function. As I read code on SO, I frequently come across the use of <code>setDT()</code> to create a data.table. Of course the use of <code>data.table()</code> is ubiquitous. I feel like I solidly comprehend the nature of <code>data.table()</code> yet the relevance of <code>setDT()</code> eludes me. <code>?setDT</code> tells me this:</p>
  
  <blockquote>
    <p><code>setDT</code> converts lists (both named and unnamed) and data.frames to data.tables <em>by reference</em>. </p>
  </blockquote>
  
  <p>as well as:</p>
  
  <blockquote>
    <p>In <code>data.table</code> parlance, all <code>set*</code> functions change their input by reference. That is, no copy is made at all, other than temporary working memory, which is as large as one column.</p>
  </blockquote>
  
  <p>So this makes me think I should only use <code>setDT()</code> to make a data.table, right? Is <code>setDT()</code> simply a list to data.table converter?  </p>
  
  <pre><code>library(data.table)
  
  a &lt;- letters[c(19,20,1,3,11,15,22,5,18,6,12,15,23)]
  b &lt;- seq(1,41,pi)
  ab &lt;- data.frame(a,b)
  d &lt;- data.table(ab)
  e &lt;- setDT(ab)
  
  str(d)
  #Classes ‘data.table’ and 'data.frame': 13 obs. of  2 variables:
  # $ a: Factor w/ 12 levels "a","c","e","f",..: 9 10 1 2 5 7 11 3 8 4 ...
  # $ b: num  1 4.14 7.28 10.42 13.57 ...
  # - attr(*, ".internal.selfref")=&lt;externalptr&gt;
  
  str(e)
  #Classes ‘data.table’ and 'data.frame': 13 obs. of  2 variables:
  # $ a: Factor w/ 12 levels "a","c","e","f",..: 9 10 1 2 5 7 11 3 8 4 ...
  # $ b: num  1 4.14 7.28 10.42 13.57 ...
  # - attr(*, ".internal.selfref")=&lt;externalptr&gt;
  </code></pre>
  
  <p>Seemingly no difference in this instance. In another instance the difference is evident:</p>
  
  <pre><code>ba &lt;- list(a,b)
  f &lt;- data.table(ba)
  g &lt;- setDT(ba)
  
  str(f)
  #Classes ‘data.table’ and 'data.frame': 2 obs. of  1 variable:
  # $ ba:List of 2
  #  ..$ : chr  "s" "t" "a" "c" ...
  #  ..$ : num  1 4.14 7.28 10.42 13.57 ...
  # - attr(*, ".internal.selfref")=&lt;externalptr&gt;
  
  str(g)
  #Classes ‘data.table’ and 'data.frame': 13 obs. of  2 variables:
  # $ V1: chr  "s" "t" "a" "c" ...
  # $ V2: num  1 4.14 7.28 10.42 13.57 ...
  # - attr(*, ".internal.selfref")=&lt;externalptr&gt;
  </code></pre>
  
  <p>When should I use <code>setDT()</code>? What makes <code>setDT()</code> relevant? Why not just make the original <code>data.table()</code> function capable of doing what <code>setDT()</code> is able to do?</p>