set.seed(120834)
DT <- data.table(var = rnorm(100))
For comparison:
> hist(DT[ , var]) #of course plot is drawn
FROM
> DT[ , hist(var)]
$breaks
[1] -3.0 -2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.5
$counts
[1] 1 1 6 7 16 20 20 12 12 3 2
$density
[1] 0.02 0.02 0.12 0.14 0.32 0.40 0.40 0.24 0.24 0.06 0.04
$mids
[1] -2.75 -2.25 -1.75 -1.25 -0.75 -0.25 0.25 0.75 1.25 1.75 2.25
$xname
[1] "var"
$equidist
[1] TRUE
attr(,"class")
[1] "histogram"
Why histdoes the latter print the object returned but not the first? Is there any way to suppress this?
I see in the code for hist.defaultthat the object is returned invisibly:
if (plot) {
plot(r, freq = freq1, col = col, border = border, angle = angle,
density = density, main = main, xlim = xlim, ylim = ylim,
xlab = xlab, ylab = ylab, axes = axes, labels = labels,
...)
invisible(r)
}
(And looking at the error from DT[ , hist(var, NA)]confirms [.data.table, really causes hist.default)
So how [.data.tabledid you manage to execute this invisible callback? Is it possible that an invisible object invisibly returns to a hidden environment, but an object from this environment is then explicitly displayed?