From c21c650d3a061bcc9a17af668fce90530a0ded29 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 24 May 2024 10:23:31 +0200 Subject: [PATCH 1/3] internally deprecate `dir = "h"/"v"` --- R/facet-wrap.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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, From 1cbcfd18e7b2fe512ff114f7a6c753ff5cacd55a Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 24 May 2024 10:29:54 +0200 Subject: [PATCH 2/3] add test --- tests/testthat/test-facet-.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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", { From 207289d6d71693323f93ddf1eb9fe140ceac30db Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Fri, 24 May 2024 10:31:13 +0200 Subject: [PATCH 3/3] amend message --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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