Skip to content

Commit

Permalink
Fix dplyr-rows (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
UchidaMizuki committed Oct 8, 2024
1 parent 60aac79 commit 3865734
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/dplyr-rows.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ timbr_rows <- function(f, x, y, by, ...) {
tibble::as_tibble() |>
dplyr::ungroup() |>
f(y, by, ...) |>
dplyr::select(!dplyr::all_of(by))
dplyr::select(!dplyr::all_of(c(group_vars(x), by)))

x$graph <- x$graph |>
tidygraph::activate("nodes") |>
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test-dplyr.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ test_that("dplyr", {
})

test_that("rows_update", {
set.seed(1234)

library(dplyr)

fr <- vec_expand_grid(key1 = letters[1:3],
Expand Down Expand Up @@ -88,4 +90,25 @@ test_that("rows_update", {
rows_patch(df,
by = c("key1", "key2")) %>%
children())

fr <- vec_expand_grid(key1 = letters[1:3],
key2 = letters[1:3],
key3 = letters[1:3]) %>%
mutate(value = row_number()) %>%
forest_by(key1, key2, key3) %>%
summarise(value = sum(value))
df <- vec_expand_grid(key2 = c("c", "a"),
key3 = c("a", "b", "c")) %>%
mutate(value = sample(1:9, n()))
fr <- fr %>%
rows_update(df,
by = c("key2", "key3")) %>%
climb(key2, key3) %>%
as_tibble() %>%
rename(value_object = value) %>%
inner_join(df %>%
rename(value_expected = value),
by = join_by(key2, key3))

expect_equal(fr$value_object, fr$value_expected)
})

0 comments on commit 3865734

Please sign in to comment.