Skip to content

Fallback for dir = 'h'/'v' #5907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions R/facet-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-facet-.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
Loading