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" #1508

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Imports:
blob (>= 1.2.0),
cli (>= 3.6.1),
DBI (>= 1.1.3),
dplyr (>= 1.1.2),
dplyr (>= 1.1.4.9000),
glue (>= 1.6.2),
lifecycle (>= 1.0.3),
magrittr,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* `across(everything())` doesn't select grouping columns created via `.by` in
`summarise()` (@mgirlich, #1493).

* `mutate()` now supports the argument `.keep = "transmute"`.

# dbplyr 2.5.0

Expand Down
10 changes: 7 additions & 3 deletions R/verb-mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
mutate.tbl_lazy <- function(.data,
...,
.by = NULL,
.keep = c("all", "used", "unused", "none"),
.keep = c("all", "used", "unused", "none", "transmute"),
.before = NULL,
.after = NULL) {
keep <- arg_match(.keep)
Expand Down Expand Up @@ -53,6 +53,7 @@ mutate.tbl_lazy <- function(.data,

out <- mutate_relocate(
out = out,
keep = keep,
before = {{ .before }},
after = {{ .after }},
names_original = names_original
Expand Down Expand Up @@ -238,11 +239,11 @@ get_mutate_dot_cols <- function(quosures, all_vars) {
)
}

mutate_relocate <- function(out, before, after, names_original) {
mutate_relocate <- function(out, keep, before, after, names_original) {
before <- enquo(before)
after <- enquo(after)

if (quo_is_null(before) && quo_is_null(after)) {
if (keep == "transmute" || (quo_is_null(before) && quo_is_null(after))) {
return(out)
}

Expand All @@ -264,6 +265,9 @@ mutate_keep <- function(out, keep, used, names_new, names_groups) {

if (keep == "all") {
names_out <- names
} else if (keep == "transmute") {
names_groups <- setdiff(names_groups, names_new)
names_out <- c(names_groups, names_new)
} else {
names_keep <- switch(
keep,
Expand Down
4 changes: 3 additions & 1 deletion man/mutate.tbl_lazy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading