You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mutated data.tables are not printed when enclosed in parentheses. #7360
As far as R is concerned, unlike base R assignments like a <- 1, which are properly invisible, dt[, a := "a"] is not an assignment and thus is visible and must be printed:
R then calls print() and dispatches to print.data.table(), which contains special code to refuse being auto-printed. To print.data.table, dt[, a := "a"] and (dt[, a := "a"]) look the same when auto-printing.
Unfortunately, we also lack the ability to force the result of [.data.table to be invisible (see #6566 and links from there for more context).
"This is a feature not a bug!"
we don't want to print for dt[, a := "a"], which silences printing, and is the same as (dt[, a := "a"]). It is normal/expected to have to add [] to get printing.
From a user intent perspective, I would assume that (dt[, a := "a"]) indicates that the user wants the result to be printed, like if they did print(dt[, a := "a"]).
From @aitap post before, it seems that it's simply not possible to distinguish between (dt[, a := "a"]) (which should print) and dt[, a := "a"] (which shouldn't print). If that's the case, then feel free to close this issue :).
From @aitap post before, it seems that it's simply not possible to distinguish between (dt[, a := "a"]) (which should print) and dt[, a := "a"] (which shouldn't print).
Is this documented somewhere?
IMHO, print(dt[, a := "a"]) is much better coding style.
In fact, implicit_assignment_linter() lints this in the similar common use case of (x <- ...) "assign with print side-effect", though this has some pushback:
The := assignment making the result "invisible" and requiring [] to make it printable is mentioned in the "Reference semantics" vignette and in a comment in the ?data.table examples.
Activity
jangorecki commentedon Oct 5, 2025
Agree this is how base R normally does.
As a workaround for now you can use
Instead
ben-schwen commentedon Oct 25, 2025
Isn't
(dt[, a := "a"])just syntactic sugar fordt[, a := "a"]?jangorecki commentedon Oct 25, 2025
But it prints
(a <- 1)aitap commentedon Oct 25, 2025
As far as R is concerned, unlike base R assignments like
a <- 1, which are properly invisible,dt[, a := "a"]is not an assignment and thus is visible and must be printed:R then calls
print()and dispatches toprint.data.table(), which contains special code to refuse being auto-printed. Toprint.data.table,dt[, a := "a"]and(dt[, a := "a"])look the same when auto-printing.Unfortunately, we also lack the ability to force the result of
[.data.tableto be invisible (see #6566 and links from there for more context).tdhock commentedon Oct 27, 2025
"This is a feature not a bug!"
we don't want to print for
dt[, a := "a"], which silences printing, and is the same as(dt[, a := "a"]). It is normal/expected to have to add [] to get printing.jangorecki commentedon Oct 27, 2025
@tdhock but it is inconsistent to <- assignment which normally also does not print, unless wrapped in (
MichaelChirico commentedon Oct 28, 2025
Isn't this related to #6631? After which adding
[]to force print should be more rare?eliocamp commentedon Oct 29, 2025
From a user intent perspective, I would assume that
(dt[, a := "a"])indicates that the user wants the result to be printed, like if they didprint(dt[, a := "a"]).From @aitap post before, it seems that it's simply not possible to distinguish between
(dt[, a := "a"])(which should print) anddt[, a := "a"](which shouldn't print). If that's the case, then feel free to close this issue :).ecoRoland2 commentedon Oct 29, 2025
Is this documented somewhere?
IMHO,
print(dt[, a := "a"])is much better coding style.MichaelChirico commentedon Oct 29, 2025
In fact,
implicit_assignment_linter()lints this in the similar common use case of(x <- ...)"assign with print side-effect", though this has some pushback:r-lib/lintr#2916
It is very common to find this in R's own manuals:
And yes, it's documented in
?"(":ecoRoland2 commentedon Oct 29, 2025
No, I mean if it is documented by data.table that
(doesn't auto-print when using:=assignment.aitap commentedon Nov 3, 2025
The
:=assignment making the result "invisible" and requiring[]to make it printable is mentioned in the "Reference semantics" vignette and in a comment in the?data.tableexamples.