Skip to content

Commit

Permalink
Require dplyr 1.1.0 and remove dead code (#1568)
Browse files Browse the repository at this point in the history
* require dplyr 1.1.0

fixes #1431

* remove if_else for dbply < 1.1.0

* Unconditionally use functions from dplyr now

* NEWS bullet

* Remove blank line

---------

Co-authored-by: Davis Vaughan <[email protected]>
  • Loading branch information
catalamarti and DavisVaughan authored Aug 15, 2024
1 parent 8d13947 commit 5e2eddc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 63 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Depends:
R (>= 3.6.0)
Imports:
cli (>= 3.4.1),
dplyr (>= 1.0.10),
dplyr (>= 1.1.0),
glue,
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
@@ -1,5 +1,7 @@
# tidyr (development version)

* tidyr now requires dplyr >=1.1.0 (#1568, @catalamarti).

# tidyr 1.3.1

* `pivot_wider` now uses `.by` and `|>` syntax for the dplyr helper message to
Expand Down
51 changes: 15 additions & 36 deletions R/complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ complete <- function(data,
UseMethod("complete")
}

on_load({
the$has_dplyr_1_1 <- packageVersion("dplyr") >= "1.0.99"
})

#' @export
complete.data.frame <- function(data,
...,
Expand All @@ -84,11 +80,7 @@ complete.data.frame <- function(data,
names <- names(out)

if (length(names) > 0L) {
if (the$has_dplyr_1_1) {
out <- dplyr::full_join(out, data, by = names, multiple = "all")
} else {
out <- dplyr::full_join(out, data, by = names)
}
out <- dplyr::full_join(out, data, by = names, multiple = "all")
} else {
# Avoid joining the 1x0 result from `expand()` with `data`.
# That causes issues when `data` has zero rows.
Expand All @@ -112,34 +104,21 @@ complete.grouped_df <- function(data,
...,
fill = list(),
explicit = TRUE) {

if (the$has_dplyr_1_1) {
reframe <- utils::getFromNamespace("reframe", ns = "dplyr")
pick <- utils::getFromNamespace("pick", ns = "dplyr")

out <- reframe(
data,
complete(
data = pick(everything()),
...,
fill = fill,
explicit = explicit
)
out <- dplyr::reframe(
data,
complete(
data = dplyr::pick(everything()),
...,
fill = fill,
explicit = explicit
)
)

drop <- dplyr::group_by_drop_default(data)
dplyr::group_by(out, !!!dplyr::groups(data), .drop = drop)
} else {
dplyr::summarise(
data,
complete(
data = dplyr::cur_data(),
...,
fill = fill,
explicit = explicit
),
.groups = "keep"
)
drop <- dplyr::group_by_drop_default(data)

}
dplyr::group_by(
out,
!!!dplyr::groups(data),
.drop = drop
)
}
39 changes: 13 additions & 26 deletions R/expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,22 @@ expand.data.frame <- function(data, ..., .name_repair = "check_unique") {

#' @export
expand.grouped_df <- function(data, ..., .name_repair = "check_unique") {

if (the$has_dplyr_1_1) {
reframe <- utils::getFromNamespace("reframe", ns = "dplyr")
pick <- utils::getFromNamespace("pick", ns = "dplyr")

out <- reframe(
data,
expand(
data = pick(everything()),
...,
.name_repair = .name_repair
)
)

drop <- dplyr::group_by_drop_default(data)
dplyr::group_by(out, !!!dplyr::groups(data), .drop = drop)
} else {
dplyr::summarise(
data,
expand(
data = dplyr::cur_data(),
...,
.name_repair = .name_repair
),
.groups = "keep"
out <- dplyr::reframe(
data,
expand(
data = dplyr::pick(everything()),
...,
.name_repair = .name_repair
)
)

}
drop <- dplyr::group_by_drop_default(data)

dplyr::group_by(
out,
!!!dplyr::groups(data),
.drop = drop
)
}

# Nesting & crossing ------------------------------------------------------
Expand Down

0 comments on commit 5e2eddc

Please sign in to comment.