Skip to content

Commit 4e88c25

Browse files
Ignore missing facet specs (#4383)
1 parent 36d5b07 commit 4e88c25

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

R/facet-.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ validate_facets <- function(x) {
329329
# Flatten a list of quosures objects to a quosures object, and compact it
330330
compact_facets <- function(x) {
331331
x <- flatten_if(x, is_list)
332-
null <- vapply(x, quo_is_null, logical(1))
333-
new_quosures(x[!null])
332+
null_or_missing <- vapply(x, function(x) quo_is_null(x) || quo_is_missing(x), logical(1))
333+
new_quosures(x[!null_or_missing])
334334
}
335335

336336
# Compatibility with plyr::as.quoted()

tests/testthat/test-facet-.r

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,25 @@ test_that("facets reject aes()", {
5252
test_that("wrap_as_facets_list() returns a quosures object with compacted", {
5353
expect_identical(wrap_as_facets_list(vars(foo)), quos(foo = foo))
5454
expect_identical(wrap_as_facets_list(~foo + bar), quos(foo = foo, bar = bar))
55-
expect_identical(wrap_as_facets_list(vars(foo, NULL, bar)), quos(foo = foo, bar = bar))
55+
56+
f <- function(x) {
57+
expect_identical(wrap_as_facets_list(vars(foo, {{ x }}, bar)), quos(foo = foo, bar = bar))
58+
}
59+
60+
f(NULL)
61+
f()
5662
})
5763

5864
test_that("grid_as_facets_list() returns a list of quosures objects with compacted", {
5965
expect_identical(grid_as_facets_list(vars(foo), NULL), list(rows = quos(foo = foo), cols = quos()))
6066
expect_identical(grid_as_facets_list(~foo, NULL), list(rows = quos(), cols = quos(foo = foo)))
61-
expect_identical(grid_as_facets_list(vars(foo, NULL, bar), NULL), list(rows = quos(foo = foo, bar = bar), cols = quos()))
67+
68+
f <- function(x) {
69+
expect_identical(grid_as_facets_list(vars(foo, {{ x }}, bar), NULL), list(rows = quos(foo = foo, bar = bar), cols = quos()))
70+
}
71+
72+
f(NULL)
73+
f()
6274
})
6375

6476
test_that("wrap_as_facets_list() and grid_as_facets_list() accept empty specs", {

0 commit comments

Comments
 (0)