moodymudskipper / tb

IN ~PROGRESS my own take on `[.data.frame`
0 stars 0 forks source link

unnest, unchop, unpack #15

Open moodymudskipper opened 4 years ago

moodymudskipper commented 4 years ago

the tidyverse also has unnest_longer, unnest_wider, unnest_auto, unnest_legacy, but we might not need this complexity.

Taking inspiration from the margin argument from apply :

We can remove created unnested columns :

These arguments could be labelled, with one (usually 1st case) or several column names.

By convention we place the n ~ BEFORE the label, so we'll have tb1[1 ~ foo := ...], this is needed because the expansions occur in the end, of the [.tb call.

I'm not completely comfortable with this decision however, as :

We could just not have ~2 and 3 and just use ~ ... for 2~ ... (vertical expansion), and use splicing to do the horizontal expansion, but not being able to delete the source column will be frustrating.

Another way is to use -- on the rhs to delete columns. but the equivalent of ((3)) ~ foo becomes ~+--foo ! Which technically is still more compact that unnest, and we might get used to the syntax, but still a bit intimidating.

moodymudskipper commented 4 years ago

Maybe if we want to keep a column that we want to unnest we just make a copy right before ?

tb[keep = nested, ~+nested]

Now it doesn't seem to me we want to keep it so often, and it makes things much easier.

moodymudskipper commented 4 years ago

should ~+ and +~ be synonyms ?

Maybe not, they'd be the same for data frame elements but a vector would behave differently depending on what's done first, so both should be supported