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/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") { 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) +})