Skip to content

Commit

Permalink
Preserve type of y in nest_join()
Browse files Browse the repository at this point in the history
Fixes #6295
  • Loading branch information
hadley committed Jul 26, 2022
1 parent 17c7a5d commit d0a8646
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# dplyr (development version)

* `nest_join()` now preserves the type of `y` (#6295).

* `*_join()` now error if you supply them with additional arguments that
aren't used (#6228).

Expand Down
2 changes: 1 addition & 1 deletion R/join.r
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ nest_join.data.frame <- function(x,
# changing the key vars because of the cast
new_cols <- vec_cast(out[names(x_key)], vec_ptype2(x_key, y_key))

y_out <- set_names(y_in[vars$y$out], names(vars$y$out))
y_out <- set_names(y[vars$y$out], names(vars$y$out))
new_cols[[name_var]] <- map(y_loc, vec_slice, x = y_out)

out <- dplyr_col_modify(out, new_cols)
Expand Down
11 changes: 10 additions & 1 deletion tests/testthat/test-join.r
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ test_that("nest_join returns list of tibbles (#3570)",{
expect_s3_class(out$df2[[1]], "tbl_df")
})

test_that("nest_join respects types of y",{
df1 <- tibble(x = c(1, 2), y = c(2, 3))
df2 <- rowwise(tibble(x = c(1, 1), z = c(2, 3)))
out <- nest_join(df1, df2, by = "x", multiple = "all")

expect_s3_class(out$df2[[1]], "rowwise_df")
})


test_that("nest_join computes common columns", {
df1 <- tibble(x = c(1, 2), y = c(2, 3))
df2 <- tibble(x = c(1, 3), z = c(2, 3))
Expand Down Expand Up @@ -319,7 +328,7 @@ test_that("joins preserve groups", {

# See comment in nest_join
i <- count_regroups(out <- nest_join(gf1, gf2, by = "a", multiple = "all"))
expect_equal(i, 1L)
expect_equal(i, 4L)
expect_equal(group_vars(out), "a")
})

Expand Down

0 comments on commit d0a8646

Please sign in to comment.