Skip to content

Print method for subclass makes := return visible output #3029

@eliocamp

Description

@eliocamp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions