title: Using lists inside data.table columns
body: <p>In <code>data.table</code> is possible to have columns of type <code>list</code> and I'm trying for the first time to benefit from this feature. I need to store for each row of my table <code>dt</code> several comments taken from an rApache web service. Each comment will have a username, datetime, and body item.</p>
  
  <p>Instead of using long strings with some weird, unusual character to separate each message from the others (like <code>|</code>), and a <code>;</code> to separate each item in a comment, I thought to use lists like this:</p>
  
  <pre><code>library(data.table)
  dt &lt;- data.table(id=1:2,
          comment=list(list(
              list(username="michele", date=Sys.time(), message="hello"),
              list(username="michele", date=Sys.time(), message="world")),
            list(
              list(username="michele", date=Sys.time(), message="hello"),
              list(username="michele", date=Sys.time(), message="world"))))
  
  &gt; dt
     id comment
  1:  1  &lt;list&gt;
  2:  2  &lt;list&gt;
  </code></pre>
  
  <p>to store all the comments added for one particular row. (also because it will be easier to convert to <code>JSON</code> later on when I need to send it back to the UI)</p>
  
  <p>However, when I try to simulate how I will be actually filling my table during production (adding single comment to a particular row), <code>R</code> either crashes or doesn't assign what I would like and then crashes:</p>
  
  <pre><code>library(data.table)
  
  &gt; library(data.table)
  &gt; dt &lt;- data.table(id=1:2, comment=vector(mode="list", length=2))
  &gt; dt$comment
  [[1]]
  NULL
  
  [[2]]
  NULL
  
  &gt; dt[1L, comment := 1] # this works
  &gt; dt$comment
  [[1]]
  [1] 1
  
  [[2]]
  NULL
  
  &gt; set(dt, 1L, "comment", list(1, "a"))  # assign only `1` and when I try to see `dt` R crashes
  Warning message:
  In set(dt, 1L, "comment", list(1, "a")) :
    Supplied 2 items to be assigned to 1 items of column 'comment' (1 unused)
  
  &gt; dt[1L, comment := list(1, "a")]       # R crashes as soon as I run
  &gt; dt[1L, comment := list(list(1, "a"))] # any of these two
  </code></pre>
  
  <p>I know I'm trying to misuse <code>data.table</code>, e.g. the way the <code>j</code> argument has been designed allows this:</p>
  
  <pre><code>dt[1L, c("id", "comment") := list(1, "a")] # lists in RHS are seen as different columns! not parts of one
  </code></pre>
  
  <p><strong>Question:</strong> So, is there a way to do the assignment I want? Or I just have to take <code>dt$comment</code> out in a variable, modify it, and then re-assign the whole column every times I need to do an update?</p>