Skip to content

Commit 47e36e2

Browse files
committed
remove/replace wrap_as_facets_list() (by compact_facets()
1 parent 4739a12 commit 47e36e2

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

R/facet-.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,9 @@ validate_facets <- function(x) {
455455
x
456456
}
457457

458-
459458
# Flatten a list of quosures objects to a quosures object, and compact it
460459
compact_facets <- function(x) {
461-
460+
x <- as_facets_list(x)
462461
proxy <- vec_proxy(x)
463462
is_list <- vapply(proxy, vec_is_list, logical(1))
464463
proxy[is_list] <- lapply(proxy[is_list], unclass)

R/facet-grid-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ grid_as_facets_list <- function(rows, cols) {
219219
check_object(cols, is_quosures, "a {.fn vars} specification", allow_null = TRUE)
220220

221221
list(
222-
rows = compact_facets(as_facets_list(rows)),
223-
cols = compact_facets(as_facets_list(cols))
222+
rows = compact_facets(rows),
223+
cols = compact_facets(cols)
224224
)
225225
}
226226

R/facet-wrap.R

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
147147
labeller <- check_labeller(labeller)
148148

149149
# Flatten all facets dimensions into a single one
150-
facets <- wrap_as_facets_list(facets)
150+
facets <- compact_facets(facets)
151151

152152
if (lifecycle::is_present(switch) && !is.null(switch)) {
153153
deprecate_warn0("2.2.0", "facet_wrap(switch)", "facet_wrap(strip.position)")
@@ -182,12 +182,6 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
182182
)
183183
}
184184

185-
# Returns a quosures object
186-
wrap_as_facets_list <- function(x) {
187-
facets_list <- as_facets_list(x)
188-
compact_facets(facets_list)
189-
}
190-
191185
#' @rdname ggplot2-ggproto
192186
#' @format NULL
193187
#' @usage NULL

tests/testthat/test-facet-.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test_that("as_facets_list() coerces character vectors", {
2121

2222
expect_identical(as_facets_list("foo"), list(foobar[1]))
2323
expect_identical(as_facets_list(c("foo", "bar")), list(foobar[1], foobar[2]))
24-
expect_identical(wrap_as_facets_list(c("foo", "bar")), foobar)
24+
expect_identical(compact_facets(c("foo", "bar")), foobar)
2525
})
2626

2727
test_that("as_facets_list() coerces lists", {
@@ -47,12 +47,12 @@ test_that("facets reject aes()", {
4747
expect_error(facet_grid(aes(foo)), "Please use `vars()` to supply facet variables", fixed = TRUE)
4848
})
4949

50-
test_that("wrap_as_facets_list() returns a quosures object with compacted", {
51-
expect_identical(wrap_as_facets_list(vars(foo)), quos(foo = foo))
52-
expect_identical(wrap_as_facets_list(~foo + bar), quos(foo = foo, bar = bar))
50+
test_that("compact_facets() returns a quosures object with compacted", {
51+
expect_identical(compact_facets(vars(foo)), quos(foo = foo))
52+
expect_identical(compact_facets(~foo + bar), quos(foo = foo, bar = bar))
5353

5454
f <- function(x) {
55-
expect_identical(wrap_as_facets_list(vars(foo, {{ x }}, bar)), quos(foo = foo, bar = bar))
55+
expect_identical(compact_facets(vars(foo, {{ x }}, bar)), quos(foo = foo, bar = bar))
5656
}
5757

5858
f(NULL)
@@ -71,12 +71,12 @@ test_that("grid_as_facets_list() returns a list of quosures objects with compact
7171
f()
7272
})
7373

74-
test_that("wrap_as_facets_list() and grid_as_facets_list() accept empty specs", {
75-
expect_identical(wrap_as_facets_list(NULL), quos())
76-
expect_identical(wrap_as_facets_list(list()), quos())
77-
expect_identical(wrap_as_facets_list(. ~ .), quos())
78-
expect_identical(wrap_as_facets_list(list(. ~ .)), quos())
79-
expect_identical(wrap_as_facets_list(list(NULL)), quos())
74+
test_that("compact_facets() and grid_as_facets_list() accept empty specs", {
75+
expect_identical(compact_facets(NULL), quos())
76+
expect_identical(compact_facets(list()), quos())
77+
expect_identical(compact_facets(. ~ .), quos())
78+
expect_identical(compact_facets(list(. ~ .)), quos())
79+
expect_identical(compact_facets(list(NULL)), quos())
8080

8181
expect_identical(grid_as_facets_list(list(), NULL), list(rows = quos(), cols = quos()))
8282
expect_identical(grid_as_facets_list(. ~ ., NULL), list(rows = quos(), cols = quos()))

0 commit comments

Comments
 (0)