Skip to content

as.data.table should remove extra attributes from extended data.frames #5699

@jangorecki

Description

@jangorecki

Spotted when investigating #5698

x = iris
class(x) = c("tbl","data.frame")
attr(x, "t1") = "a"
y = as.data.table(x)
attr(y, "t1")
#[1] "a"       ## should be NULL
class(y)
#[1] "data.table" "data.frame"

We should assume creator of custom class provides correct data.frame method that clear any extra attributes

as.data.frame.tbl = function(x) {
  attr(x, "t1") = NULL
  class(x) = "data.frame"
  x
}
z = as.data.frame(x)
attr(z, "t1")
#NULL

So then consistency can be retained, as described in #5698

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions