Skip to content

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