Skip to content

Keep the column attribute label in bind_rows #7665

@ynsec37

Description

@ynsec37

The bind_rows output miss the label of column as shown in the below

library(dplyr, warn.conflicts = FALSE)

packageVersion("dplyr")
#> [1] '1.1.4'

df1 <- tibble(x = 1:2, y = letters[1:2])
df2 <- tibble(x = 4:5, z = 1:2)

attr(df1$x, "label") <- "df1 lable x"
attr(df2$x, "label") <- "df2 lable x"


output1 <- bind_rows(list(df1, df2))
attributes(output1$x)
#> NULL

output2 <- data.table::rbindlist(list(df1, df2), use.names = TRUE, fill = TRUE) |>
  as.data.frame()
attributes(output2$x)
#> $label
#> [1] "df1 lable x"

output3 <- data.table::rbindlist(list(df2, df1), use.names = TRUE, fill = TRUE) |>
  as.data.frame()
attributes(output3$x)
#> $label
#> [1] "df2 lable x"

Created on 2025-02-26 with reprex v2.1.1

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