cynkra / constructive

Display Idiomatic Code to Construct Most R Objects
https://cynkra.github.io/constructive
Other
132 stars 6 forks source link

attribute order #444

Open moodymudskipper opened 5 months ago

moodymudskipper commented 5 months ago

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")

We have several ways to address this :

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