Skip to content

Commit 7cc7b3d

Browse files
Fix compatibility with dplyr 1.0.0 (#140)
* Use group_by() before group_indices() * Ensure the result of summairse() returns only one row per group * Explicitly sort the columns of data.frame * Use expect_equivalent()
1 parent 444845c commit 7cc7b3d

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

R/gghighlight.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,11 @@ calculate_group_info <- function(data, mapping, extra_vars = NULL) {
296296
}
297297

298298
# calculate group IDs with extra_data
299-
group_ids <- dplyr::group_indices(
299+
group_df <- dplyr::group_by(
300300
dplyr::bind_cols(data_evaluated, extra_data),
301301
!!!syms(c(group_cols, names(extra_data)))
302302
)
303+
group_ids <- dplyr::group_indices(group_df)
303304

304305
list(
305306
data = data_evaluated,
@@ -480,6 +481,11 @@ calculate_grouped <- function(data, predicates, max_highlight, group_ids) {
480481
data_predicated <- dplyr::group_by(data_predicated, !!VERY_SECRET_COLUMN_NAME := !!group_ids)
481482
data_predicated <- dplyr::summarise(data_predicated, !!!predicates)
482483

484+
group_with_multiple_result <- anyDuplicated(dplyr::pull(data_predicated, !!VERY_SECRET_COLUMN_NAME))
485+
if (!identical(group_with_multiple_result, 0L)) {
486+
abort("", "gghighlight_invalid_group_predicate_error")
487+
}
488+
483489
cols <- choose_col_for_filter_and_arrange(data_predicated, VERY_SECRET_COLUMN_NAME)
484490

485491
# Filter by the logical predicates.

tests/testthat/helpers.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
expect_equal_layer <- function(x, y) {
22
x$mapping <- x$mapping[sort(names(x$mapping))]
33
y$mapping <- y$mapping[sort(names(y$mapping))]
4+
x$data <- x$data[, sort(colnames(x$data))]
5+
y$data <- y$data[, sort(colnames(y$data))]
46
expect_equal(x, y)
57
}
68

tests/testthat/test-calculate-group.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ test_that("calculate_group_info() works", {
3232
# if there is group mapping, use it
3333
d_expect_group <- d_expect
3434
d_expect_group$group <- d$type == "a"
35-
expect_equal(calculate_group_info(d, aes(x, y, group = (type == "a"), colour = type)),
36-
list(data = d_expect_group, id = c(2, 2, 2, 1, 1, 1, 1), key = aes()))
35+
res <- calculate_group_info(d, aes(x, y, group = (type == "a"), colour = type))
36+
expect_equal(res$data, d_expect_group[, colnames(res$data)])
37+
expect_equal(res$id, c(2, 2, 2, 1, 1, 1, 1))
38+
expect_equal(res$key, aes())
3739
})
3840

3941

tests/testthat/test-label.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ test_that("generate_labelled_layer() geenrates a layer for label.", {
7474

7575
expect_equal(generate_labelled_layer(list(l_point), list(g_info), quo(no_such_column), list(fill = "white"), nrow(d)),
7676
NULL)
77-
expect_equal(generate_labelled_layer(list(l_line), list(g_info), type2_quo, list(fill = "white"), 2),
78-
ggrepel::geom_label_repel(aes(x, y, colour = type, label = type2), d[c(2, 4), ], fill = "white"))
77+
expect_equivalent(
78+
generate_labelled_layer(list(l_line), list(g_info), type2_quo, list(fill = "white"), 2),
79+
ggrepel::geom_label_repel(aes(x, y, colour = type, label = type2), d[c(2, 4), ], fill = "white")
80+
)
7981
expect_equal(generate_labelled_layer(list(l_bar), list(g_info), type2_quo, list(fill = "white"), nrow(d)),
8082
list())
8183
# Do not generate labels when the data is more than max_labels

0 commit comments

Comments
 (0)