diff --git a/NEWS.md b/NEWS.md index de3e87cee3..71d565db9a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -44,7 +44,8 @@ * (Internal) Applying defaults in `geom_sf()` has moved from the internal `sf_grob()` to `GeomSf$use_defaults()` (@teunbrand). * `facet_wrap()` has new options for the `dir` argument to more precisely - control panel directions (@teunbrand, #5212) + control panel directions. Internally `dir = "h"` or `dir = "v"` is deprecated + (@teunbrand, #5212). * Prevented `facet_wrap(..., drop = FALSE)` from throwing spurious errors when a character facetting variable contained `NA`s (@teunbrand, #5485). * When facets coerce the faceting variables to factors, the 'ordered' class diff --git a/R/facet-wrap.R b/R/facet-wrap.R index 720e2e8e37..dfe487a3f8 100644 --- a/R/facet-wrap.R +++ b/R/facet-wrap.R @@ -586,6 +586,21 @@ wrap_layout <- function(id, dims, dir) { as.table <- TRUE n <- attr(id, "n") + if (nchar(dir) != 2) { + # Should only occur when `as.table` was not incorporated into `dir` + dir <- switch(dir, h = "lt", v = "tl") + deprecate_soft0( + "3.5.2", + what = I("Internal use of `dir = \"h\"` and `dir = \"v\"` in `facet_wrap()`"), + details = I(c( + "The `dir` argument should incorporate the `as.table` argument.", + paste0("Falling back to `dir = \"", dir, "\"`.") + )) + ) + } + + dir <- arg_match0(dir, c("lt", "tl", "lb", "bl", "rt", "tr", "rb", "br")) + ROW <- switch( dir, lt = , rt = (id - 1L) %/% dims[2] + 1L, diff --git a/tests/testthat/test-facet-.R b/tests/testthat/test-facet-.R index 8573ef80d5..9e536798a8 100644 --- a/tests/testthat/test-facet-.R +++ b/tests/testthat/test-facet-.R @@ -325,6 +325,18 @@ test_that("facet_wrap `axes` can draw inner axes.", { expect_equal(sum(vapply(left, inherits, logical(1), "absoluteGrob")), 2) }) +test_that("facet_wrap throws deprecation messages", { + withr::local_options(lifecycle_verbosity = "warning") + + facet <- facet_wrap(vars(year)) + facet$params$dir <- "h" + + lifecycle::expect_deprecated( + ggplot_build(ggplot(mpg, aes(displ, hwy)) + geom_point() + facet), + "Internal use of" + ) +}) + # Variable combinations --------------------------------------------------- test_that("zero-length vars in combine_vars() generates zero combinations", {