Skip to content
Closed
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
17 changes: 15 additions & 2 deletions R/uncount.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,21 @@ uncount.data.frame <- function(data, weights, ..., .remove = TRUE, .id = NULL) {

# NOTE it was decided to also remove grouping variables as there is no clear
# best answer. See https://github.com/tidyverse/tidyr/pull/1070
if (.remove && quo_is_symbol(weights_quo)) {
out[[as_string(get_expr(weights_quo))]] <- NULL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change

# Handle removal of weight column for both direct symbols and .data pronoun
# Fixes #1583 - support for .data$column syntax
if (.remove) {
weights_expr <- get_expr(weights_quo)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change

if (quo_is_symbol(weights_quo)) {
# Simple case: uncount(df, w)
out[[as_string(weights_expr)]] <- NULL
} else if (is_call(weights_expr, "$", n = 2) &&
identical(weights_expr[[2]], sym(".data"))) {
Comment on lines +56 to +57

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[air] reported by reviewdog 🐶

Suggested change
} else if (is_call(weights_expr, "$", n = 2) &&
identical(weights_expr[[2]], sym(".data"))) {
} else if (
is_call(weights_expr, "$", n = 2) &&
identical(weights_expr[[2]], sym(".data"))
) {

# .data pronoun case: uncount(df, .data$w)
col_name <- as_string(weights_expr[[3]])
out[[col_name]] <- NULL
}
}

if (!is.null(.id)) {
Expand Down
Loading