From fc59137d2aa29fa56d81b25283607d29f59e0a57 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 26 Nov 2025 13:27:24 +0100 Subject: [PATCH 1/3] Fix bug --- R/utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utilities.R b/R/utilities.R index 598b9a8fc3..2aa6ab5b42 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -927,7 +927,7 @@ compute_data_size <- function(data, size, default = 0.9, panels <- arg_match0(panels, c("across", "by", "ignore")) if (panels == "across") { - res <- split(data[[var]], data$PANEL, drop = FALSE) + res <- split(data[[var]], data$PANEL, drop = TRUE) res <- vapply(res, resolution, FUN.VALUE = numeric(1), ...) res <- min(res, na.rm = TRUE) } else if (panels == "by") { From f8835f9f247d872055ceca3816e16c8434ab5cc7 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 26 Nov 2025 13:42:44 +0100 Subject: [PATCH 2/3] add test --- DESCRIPTION | 2 +- tests/testthat/test-utilities.R | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 01f91fcb9a..da78c46c3d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -70,7 +70,7 @@ Suggests: rpart, sf (>= 0.7-3), svglite (>= 2.1.2), - testthat (>= 3.1.5), + testthat (>= 3.3.0), tibble, vdiffr (>= 1.0.6), xml2 diff --git a/tests/testthat/test-utilities.R b/tests/testthat/test-utilities.R index 66e380c973..33fb9fb5cc 100644 --- a/tests/testthat/test-utilities.R +++ b/tests/testthat/test-utilities.R @@ -197,3 +197,13 @@ test_that("fallback_palette finds palettes", { pal <- fallback_palette(sc) expect_true(is_discrete_pal(pal)) }) + +test_that("compute_data_size handles gnarly cases", { + # Test missing levels + df <- data_frame0( + x = seq(0, 20, by = 2), + PANEL = factor(rep("B", 11), levels = c("A", "B")) + ) + new <- compute_data_size(df, size = NULL, target = "width", default = 1) + expect_all_equal(new$width, 2) +}) From da9cf53e0c144107ceaf7784d341ecfbe042b2c8 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 3 Dec 2025 15:45:37 +0100 Subject: [PATCH 3/3] Add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index a252538302..714784d06f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ (@lgaborini, #6724) * Added new argument `geom_curve(shape)` that will be passed down to `grid::curveGrob()` (@fmarotta, #5998). +* Fixed a regression where default `width` was miscalculated when some panels + are empty (@teunbrand, #6758) # ggplot2 4.0.1