4

I found that often when I try to print in console a data.table (eg. by typing dt and pressing Enter), it will not print anything. So I have to type it two or three times (like dt;dt;dt) and then it will get printed.

Not a big deal, but I' curious why it happens? Is that me not doing something right, or is it a glitch in data.table package?

Sorry, I can't make reprex - as this situation does not seem to occur deterministically. But It often happens after in a series of mortifications made to data.table (e.f. dt[, a:=b+c][, aa:=2*a])

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
IVIM
  • 2,167
  • 1
  • 15
  • 41

1 Answers1

6

It is a known issue and can be solved by adding an extra [] at the end, e.g. dt[, a:=b+c][, aa:=2*a][].

From the data.table FAQ:

Why do I have to type DT sometimes twice after using := to print the result to console?

This is an unfortunate downside to get #869 to work. If a := is used inside a function with no DT[] before the end of the function, then the next time DT is typed at the prompt, nothing will be printed. A repeated DT will print. To avoid this: include a DT[] after the last := in your function. If that is not possible (e.g., it's not a function you can change) then print(DT) and DT[] at the prompt are guaranteed to print. As before, adding an extra [] on the end of := query is a recommended idiom to update and then print; e.g.> DT[,foo:=3L][].

s_baldur
  • 29,441
  • 4
  • 36
  • 69