elixir-explorer / explorer

Series (one-dimensional) and dataframes (two-dimensional) for fast and elegant data exploration in Elixir
https://hexdocs.pm/explorer
MIT License
1.12k stars 123 forks source link

Support dplyr-like `keep` argument for `mutate` functions #965

Closed brendon9x closed 3 months ago

brendon9x commented 3 months ago

It would be nice to have the keep argument on mutate functions that Dplyr has. From their docs:

.keep Control which columns from .data are retained in the output. Grouping columns and columns created by ... are always kept.

"all" retains all columns from .data. This is the default.

"used" retains only the columns used in ... to create new columns. This is useful for checking your work, as it displays inputs and outputs side-by-side.

"unused" retains only the columns not used in ... to create new columns. This is useful if you generate new columns, but no longer need the columns used to generate them.

"none" doesn't retain any extra columns from .data. Only the grouping variables and columns created by ... are kept.

Using myself as an example, I often find I need to create temporary working columns that I need to break up the computations to keep it readable. In those cases, keep: :none or keep: :used options really help. Especially in Livebook mode where readability trumps performance.

I am currently chaining mutate with select and it's fine, but it's a bit of work to keep them aligned with the number of mutations gets large. Being able to avoid this would be nice.

josevalim commented 3 months ago

A PR that supports :all and :none would be welcome. We can support others but those are the easier ones to get started with. The implementation can be a simple call to select. :)