From 6f64854523871bd3df6ac1993360fece4ca97aaa Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Sep 2025 00:59:27 +0900 Subject: [PATCH 1/4] Add a failing test --- tests/testthat/test-scales-breaks-labels.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-scales-breaks-labels.R b/tests/testthat/test-scales-breaks-labels.R index 70a7e0ddcb..335af945f1 100644 --- a/tests/testthat/test-scales-breaks-labels.R +++ b/tests/testthat/test-scales-breaks-labels.R @@ -18,10 +18,14 @@ test_that("labels don't have to match null breaks", { test_that("labels accept expressions", { labels <- parse(text = paste0(1:4, "^degree")) - sc <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3)) + sc1 <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3)) - expect_equal(sc$get_breaks(), 1:4) - expect_equal(sc$get_labels(), as.list(labels)) + # classed labels should also work (#6638) + labels <- structure(labels, class = "foo") + sc2 <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3)) + + expect_equal(sc1$get_labels(), as.list(labels)) + expect_equal(sc2$get_labels(), as.list(labels)) }) test_that("labels don't have extra spaces", { From 5d78489854403cc6941965e48b25ffb4b353498e Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Sep 2025 00:59:40 +0900 Subject: [PATCH 2/4] Unclass expression labels --- R/scale-.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/scale-.R b/R/scale-.R index df2046c25e..672328686f 100644 --- a/R/scale-.R +++ b/R/scale-.R @@ -1190,7 +1190,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale, labels <- lapply(labels, `[`, 1) } if (is.expression(labels)) { - labels <- as.list(labels) + labels <- as.list(unclass(labels)) } labels @@ -1438,7 +1438,7 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale, } if (is.expression(labels)) { - labels <- as.list(labels) + labels <- as.list(unclass(labels)) } labels }, @@ -1689,7 +1689,7 @@ ScaleBinned <- ggproto("ScaleBinned", Scale, ) } if (is.expression(labels)) { - labels <- as.list(labels) + labels <- as.list(unclass(labels)) } labels }, From 795a7cd34cb9c62e7209c7943b45e17d123549a4 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Sep 2025 01:04:28 +0900 Subject: [PATCH 3/4] Fix test --- tests/testthat/test-scales-breaks-labels.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-scales-breaks-labels.R b/tests/testthat/test-scales-breaks-labels.R index 335af945f1..893ce2bfc6 100644 --- a/tests/testthat/test-scales-breaks-labels.R +++ b/tests/testthat/test-scales-breaks-labels.R @@ -21,8 +21,8 @@ test_that("labels accept expressions", { sc1 <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3)) # classed labels should also work (#6638) - labels <- structure(labels, class = "foo") - sc2 <- scale_y_continuous(breaks = 1:4, labels = labels, limits = c(1, 3)) + classed_labels <- structure(labels, class = "foo") + sc2 <- scale_y_continuous(breaks = 1:4, labels = classed_labels, limits = c(1, 3)) expect_equal(sc1$get_labels(), as.list(labels)) expect_equal(sc2$get_labels(), as.list(labels)) From a34e0a34fd1ab3772c34e1ac15bb888c6b782161 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Wed, 24 Sep 2025 01:04:52 +0900 Subject: [PATCH 4/4] Update NEWS --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 0fd950dcf6..7b0fdb280d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,7 @@ * Fixed regression where `draw_key_rect()` stopped using `fill` colours (@mitchelloharawild, #6609). * Fixed regression where `scale_{x,y}_*()` threw an error when an expression - object is set to `labels` argument (@yutannihilation, #6617). + object is set to `labels` argument (@yutannihilation, #6617, #6638). * Allow `stat` in `geom_hline`, `geom_vline`, and `geom_abline`. (@sierrajohnson, #6559)