Skip to content

relocate() drops attributes attached to bare data frames #6341

@DavisVaughan

Description

@DavisVaughan

Since this is mainly just using x[i] it should be using dplyr_col_select() internally, which patches the [ method of base R data frames and data.table objects to retain attributes

library(dplyr)

df <- vctrs::data_frame(x = 1, y = 2)
attr(df, "foo") <- "bar"

out <- relocate(df, y, .before = x)

attr(out, "foo")
#> NULL

Since mutate() also uses relocate(), that should fix the same kind of issue that comes from mutate() + .before

library(dplyr)

df <- vctrs::data_frame(x = 1, y = 2)
attr(df, "foo") <- "bar"

out <- mutate(df, z = 3, .before = x)

attr(out, "foo")
#> NULL

Metadata

Metadata

Assignees

Labels

bugan unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions