moodymudskipper / tb

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

could we move columns ? or mutate at a selected position ? #25

Open moodymudskipper opened 4 years ago

moodymudskipper commented 4 years ago

Reordering can be done in j using s(), but maybe we can mutate at some position ?

@ is used for slots so could be used unambiguously. The parser is flexible enough so that 1@.(2) is legal, though 1@2 and 1@(2) are not.

This could mutate Species and place it before Sepal.Length :

iris %tb>% .[Species@Sepal.Length := toupper(.)]

This could just move it

iris %tb>% .[Species@Sepal.Length]

Move everything starting with a before anything numeric :

iris %tb>% .[?"^a"@.(?is.numeric)]

This deals with before, not after.

Another possible syntax

iris %tb>% .[Species < Sepal.Length := toupper(.)]
iris %tb>% .[Species < Sepal.Length]
iris %tb>% .[?"^a" < ?is.numeric]

This makes < and > special though, and could lead to ambiguities if it were used to get a logical index, but I don't see an example when we'd want that. maybe something like : apply this transformation on columns with low nchar ?

I don't know how intuitive this is however so let's let it rest

moodymudskipper commented 4 years ago

or an after()/before() set of pseudo functions ? It would work a bit like s() but with a first argument for position :

mtcars %tb>% .[after(disp, foo = cyl)]

I think it makes a lot of sense, it just adds magical functions.

tb recognizes that after and before cannot be called in i and j, so feeds them to the ...