I'm extending data.table class and I'm having a problem. When defining a custom print method operations with := print the object instead of returning it invisibly.
library(data.table)
dt <- data.table(x = 1)
dt[, y := 1] # No output. Correct!
setattr(dt, "class", c("someclass", class(dt)))
dt[, y := 1] # still no output. Yey!
print.someclass <- function(x, ...) {
NextMethod("print")
# maybe other things
}
dt[, y := 1] # there's output, Noooo!
(The output doesn't seem to appear when reprexed, but it's there in interactive mode, please test)
I don't know what I'm doing wrong and I cannot find much documentation on this.