Open moodymudskipper opened 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.
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
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 fromapply
:tb1[1 ~ foo]
expands horizontally (similar tounchop()
andunnest_longer()
)tb1[2 ~ foo]
expands vertically (similar tounpack
andunnest_wider
)tb1[3 ~ foo]
expands in both directions (similar tounnest()
,unnest_legacy()
, orunnest_auto()
We can remove created unnested columns :
tb1[((1)) ~ foo]
tb1[((2)) ~ foo]
tb1[((3)) ~ foo]
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 havetb1[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
~ ...
for2~ ...
(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 thatunnest
, and we might get used to the syntax, but still a bit intimidating.