Skip to content

as_tibble.data.table() method?  #5698

@ccsarapas

Description

@ccsarapas

(I originally requested this at tidyverse/tibble/issues/1555, but they suggested requesting here instead.)

Would you consider adding a data.table method to as_tibble()? On extremely cursory testing, it may be as simple as adapting as_tibble.data.frame() with an extra line to remove the .internal.selfref attribute:

library(tibble)
library(data.table)
data(mpg, package = "ggplot2")

# two identical tibbles
mpg2 <- copy(mpg)
identical(mpg, mpg2)
#> [1] TRUE

# after converting to data.table and back to tibble, no longer identical
setDT(mpg2)
mpg2 <- as_tibble(mpg2)
identical(mpg, mpg2)
#> [1] FALSE

# identical again after removing ".internal.selfref" attribute
attr(mpg2, ".internal.selfref") <- NULL
identical(mpg, mpg2)
#> [1] TRUE

Created on 2023-09-22 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions