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

attribute order #444

Open
moodymudskipper opened this issue Jul 1, 2024 · 1 comment
Open

attribute order #444

moodymudskipper opened this issue Jul 1, 2024 · 1 comment
Milestone

Comments

@moodymudskipper
Copy link
Collaborator

I don't know if we'll ever get there because the value is modest and the effort is non trivial, but it's interesting and if constructive needs to really "tell the truth" it should know about this.

x <- structure(1, names = "a", foo = 2)
y <- structure(1, foo = 2, names = "a")
  • identical() doesn't care about attribute order (by default!)
  • construct() doesn't either
  • dput() and construct_dput() mostly care, but the fact that names are inlined means names is always the first attribute in generated objects.

We have several ways to address this :

  • The simplest one is to manage to always trigger name repair with construct_dput()
  • We can also integrate an attribute order check in is_corrupted_, to use the next constructor, but that means passing a new arg to it and researching idiomatic attribute order
  • We can modify the attribute reparation step and call |> (`attributes<-`)(attributes(x)[c(3,1,2)])

The last one seems the most appealing to me.

I think we have a new arg in construct(), caught by the repair_attributes_ function, this function generates a reordering sequence, NULL if no sorting is required, then .cstr_repair_attributes() builds the code. In some cases like data.frame and variants, we might just add [] to reorder the attributes.

It might that we don't change much code if we turn it on by default, though I suspect the names attributes and the data frame subsetting shuffle will. So better keep optional, probably

@moodymudskipper moodymudskipper added this to the 1.1.0 milestone Jul 2, 2024
@moodymudskipper
Copy link
Collaborator Author

This requires going through every constructor and identify which attributes are set and in which order, and do it for every new constructor in the future. I think it also needs to be done in one pass so probably not worth it until requested, moving to backlog

@moodymudskipper moodymudskipper modified the milestones: 1.1.0, backlog Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant