R Notebook and R Markdown documents "tricked" by data.table `:=` assignment?

430 views Asked by At

The title of this question refers back to this question that was answered a couple of years ago. The issue raised and resolved there with data.table and knitr seems to have reappeared with the relatively new R Notebooks from RStudio and R Markdown.

In brief, as covered in data.table FAQ 2.21 and 2.22 a data.table should not print when using :=, the assignment by reference operator. The print behavior was a past issue with R and knitr that the data.table folks appear to have spent a lot of effort fixing (for instance, see their GitHub Issue #505). But now it's happening again with R Notebooks, both in interactive mode and using Knit to HTML.

The previous question pretty much covers the minimal, complete, and verifiable example of the behavior. Put simply, this statement will print when running it from a R Notebook or R Markdown document:

DT[, x := sum(y)]

It does not print when run from the Console or a standard R Script file.

I'm using the most recent version of data.table available through CRAN, v1.10.0, and RStudio v1.0.44.

Some workarounds noted in the previous question, such as using <- or wrapping the operations with invisible(), do work with the R Notebooks. They're not overly burdensome to use, yet as also noted in that previous question, they're not ideal fixes.

I'm a grateful user of this amazing software but am still fairly unsophisticated on the inner workings. If I'm missing something obvious or a duplicate question somewhere, my apologies. And perhaps I should be posting this issue with RStudio instead of here. Cheers.

0

There are 0 answers