Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutate() now supports the argument .keep = "transmute" #176

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

apalacio9502
Copy link

Hi @krlmlr,

This merge request seeks to support the new .keep = "transmute" argument in the mutate, based on the dplyr pull request tidyverse/dplyr#7038

Below I leave an example comparing transmute with mutate(.keep = "transmute")

example <- tibble(
  group = c("a", "a", "b", "b"),
  old = c(1, 2, 3, 4)
)

example <- duckplyr::as_duckplyr_df(example)

# transmute --------------------------------------------------------------------

example %>% transmute(
  group,
  new = old * 2,
  old
)

materializing:
---------------------
--- Relation Tree ---
---------------------
Projection ["group" as group, *("old", 2.0) as new, "old" as old]
r_dataframe_scan(0x7fbd82db4148)

---------------------
-- Result Columns  --
---------------------
- group (VARCHAR)
- new (DOUBLE)
- old (DOUBLE)

# A tibble: 4 × 3
group   new   old
<chr> <dbl> <dbl>
1 a         2     1
2 a         4     2
3 b         6     3
4 b         8     4

# mutate(.keep = "transmute") --------------------------------------------------

example %>% mutate(
  .keep = "transmute",
  group,
  new = old * 2,
  old
) 

materializing:
---------------------
--- Relation Tree ---
---------------------
Projection ["group" as group, "new" as new, "old" as old]
Projection ["group" as group, "old" as old, "new" as new]
Projection ["group" as group, "old" as old, *("old", 2.0) as new]
Projection ["group" as group, "old" as old]
r_dataframe_scan(0x7fbd6485f588)

---------------------
-- Result Columns  --
---------------------
- group (VARCHAR)
- new (DOUBLE)
- old (DOUBLE)

# A tibble: 4 × 3
group   new   old
<chr> <dbl> <dbl>
1 a         2     1
2 a         4     2
3 b         6     3
4 b         8     4

Regards,

@krlmlr
Copy link
Member

krlmlr commented Jun 24, 2024

Thanks for the PR! It's a bit early for me to review it, let's wait on what happens in dplyr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants