Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DavisVaughan opened this issue Jul 20, 2022 · 0 comments · Fixed by #6342
Closed

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

DavisVaughan opened this issue Jul 20, 2022 · 0 comments · Fixed by #6342
Assignees
Labels
bug an unexpected problem or unintended behavior

Comments

@DavisVaughan
Copy link
Member

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
@DavisVaughan DavisVaughan added the bug an unexpected problem or unintended behavior label Jul 20, 2022
@DavisVaughan DavisVaughan self-assigned this Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant