Skip to content

Commit 418d1f8

Browse files
committed
quick fix behaviour of combine_vars() with multiple data frames
1 parent 3b69172 commit 418d1f8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

R/facet-.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ combine_vars <- function(data, env = emptyenv(), vars = NULL, drop = TRUE) {
563563
if (drop) {
564564
new <- unique_combs(new)
565565
}
566-
base <- rbind(base, df.grid(old, new))
566+
base <- unique(rbind(base, df.grid(old, new)))
567567
}
568568

569569
if (empty(base)) {

tests/testthat/test-facet-.r

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,30 @@ test_that("facet gives clear error if ", {
204204
)
205205
})
206206

207+
# Variable combinations ---------------------------------------------------
208+
209+
test_that("combine_vars() generates the correct combinations with multiple data frames", {
210+
df <- expand.grid(letter = c("a", "b"), number = c(1, 2), boolean = c(TRUE, FALSE))
211+
212+
vars <- vars(letter = letter, number = number)
213+
expect_identical(
214+
combine_vars(list(df), vars = vars),
215+
combine_vars(list(df, df), vars = vars)
216+
)
217+
expect_identical(
218+
combine_vars(list(df), vars = vars),
219+
combine_vars(list(df, df[character(0)]), vars = vars)
220+
)
221+
expect_identical(
222+
combine_vars(list(df), vars = vars),
223+
combine_vars(list(df, df["letter"]), vars = vars)
224+
)
225+
expect_identical(
226+
combine_vars(list(df), vars = vars),
227+
combine_vars(list(df, df[c("letter", "number")]), vars = vars)
228+
)
229+
})
230+
207231

208232
# Visual tests ------------------------------------------------------------
209233

0 commit comments

Comments
 (0)