Skip to content

select() does not preserve attributes for data frames #5294

@stibu81

Description

@stibu81

According to the documentation, select() should preserve attributes ("Data frame attributes are preserved." in section Value). However, this seems to work only for tibbles, not for data frames. This is an reproducible example:

mtcars_df <- mtcars
attr(mtcars_df, "test") <- TRUE
mtcars_tib <- as_tibble(mtcars_df)
attr(mtcars_df, "test")
attr(mtcars_tib, "test")

attr(dplyr::select(mtcars_df), "test")
attr(dplyr::select(mtcars_tib), "test")

With dplyr 0.8.5, all the four calls of attr() return TRUE as expected. But with dplyr 1.0.0, attr(dplyr::select(mtcars_df), "test") returns NULL.

The result does not change, if some columns are selected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorverbs 🏃‍♀️

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions