Skip to content

Commit 8f3a4ba

Browse files
authored
Fallback for dir = 'h'/'v' (#5907)
* internally deprecate `dir = "h"/"v"` * add test * amend message
1 parent 6c975e8 commit 8f3a4ba

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
* (Internal) Applying defaults in `geom_sf()` has moved from the internal
4545
`sf_grob()` to `GeomSf$use_defaults()` (@teunbrand).
4646
* `facet_wrap()` has new options for the `dir` argument to more precisely
47-
control panel directions (@teunbrand, #5212)
47+
control panel directions. Internally `dir = "h"` or `dir = "v"` is deprecated
48+
(@teunbrand, #5212).
4849
* Prevented `facet_wrap(..., drop = FALSE)` from throwing spurious errors when
4950
a character facetting variable contained `NA`s (@teunbrand, #5485).
5051
* When facets coerce the faceting variables to factors, the 'ordered' class

R/facet-wrap.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,21 @@ wrap_layout <- function(id, dims, dir) {
586586
as.table <- TRUE
587587
n <- attr(id, "n")
588588

589+
if (nchar(dir) != 2) {
590+
# Should only occur when `as.table` was not incorporated into `dir`
591+
dir <- switch(dir, h = "lt", v = "tl")
592+
deprecate_soft0(
593+
"3.5.2",
594+
what = I("Internal use of `dir = \"h\"` and `dir = \"v\"` in `facet_wrap()`"),
595+
details = I(c(
596+
"The `dir` argument should incorporate the `as.table` argument.",
597+
paste0("Falling back to `dir = \"", dir, "\"`.")
598+
))
599+
)
600+
}
601+
602+
dir <- arg_match0(dir, c("lt", "tl", "lb", "bl", "rt", "tr", "rb", "br"))
603+
589604
ROW <- switch(
590605
dir,
591606
lt = , rt = (id - 1L) %/% dims[2] + 1L,

tests/testthat/test-facet-.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,18 @@ test_that("facet_wrap `axes` can draw inner axes.", {
325325
expect_equal(sum(vapply(left, inherits, logical(1), "absoluteGrob")), 2)
326326
})
327327

328+
test_that("facet_wrap throws deprecation messages", {
329+
withr::local_options(lifecycle_verbosity = "warning")
330+
331+
facet <- facet_wrap(vars(year))
332+
facet$params$dir <- "h"
333+
334+
lifecycle::expect_deprecated(
335+
ggplot_build(ggplot(mpg, aes(displ, hwy)) + geom_point() + facet),
336+
"Internal use of"
337+
)
338+
})
339+
328340
# Variable combinations ---------------------------------------------------
329341

330342
test_that("zero-length vars in combine_vars() generates zero combinations", {

0 commit comments

Comments
 (0)