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

mutate() discards user-defined attributes #3884

Closed
choisy opened this issue Oct 8, 2018 · 2 comments
Closed

mutate() discards user-defined attributes #3884

choisy opened this issue Oct 8, 2018 · 2 comments

Comments

@choisy
Copy link

choisy commented Oct 8, 2018

The functions filter() and mutate() behave differently in what regards user-defined attributes.
Below is an example. Let's start by adding an attribute to a data frame:

attr(mtcars, "my_attribute_name") <- "my_attribute_value"

We can see the attributes of this data frame:

attributes(mtcars)

The function filter() behaves as expected in the sense that it does not affect the attributes of the data frame (apart from row.names of course):

mtcars %>%
  filter(mpg > 20) %>%
  attributes()

On the other hand, the function mutate() does affect the attributes of the data. Specifically, the above user-defined attribute is discarded (the other ones are unaffected):

mtcars %>%
  mutate(a_new_variable = 3) %>%
  attributes()

I think that it would be nicer if mutate() preserved the user-defined attributes as filter() does.

@hadley
Copy link
Member

hadley commented Oct 8, 2018

Duplicate of #3429

@hadley hadley marked this as a duplicate of #3429 Oct 8, 2018
@hadley hadley closed this as completed Oct 8, 2018
@lock
Copy link

lock bot commented Apr 6, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Apr 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants