From 67d6fda28174c6e1d2ad13cef7bc73afb5b96d5e Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 28 May 2025 14:36:05 +0200 Subject: [PATCH 1/3] handle warnings about function-labels --- R/labels.R | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/R/labels.R b/R/labels.R index 309f38902e..09f0490759 100644 --- a/R/labels.R +++ b/R/labels.R @@ -80,10 +80,17 @@ setup_plot_labels <- function(plot, layers, data) { extra_labels <- setdiff(names(plot_labels), known_labels) if (length(extra_labels) > 0) { - extra_labels <- paste0( - "{.code ", extra_labels, " = \"", plot_labels[extra_labels], "\"}" + + warn_labels <- plot_labels[extra_labels] + warn_labels <- ifelse( + vapply(warn_labels, is.function, logical(1)), + "{.cls function}", + paste0("{.val ", warn_labels, "}") ) + + extra_labels <- paste0("{.field ", extra_labels, "} : ", warn_labels) names(extra_labels) <- rep("*", length(extra_labels)) + cli::cli_warn(c( "Ignoring unknown labels:", extra_labels From dcac34b0c21a1f7c1908d830498b86522f2d3406 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 28 May 2025 14:46:40 +0200 Subject: [PATCH 2/3] include in test --- tests/testthat/test-labels.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-labels.R b/tests/testthat/test-labels.R index 4befce8af6..be947ee1c9 100644 --- a/tests/testthat/test-labels.R +++ b/tests/testthat/test-labels.R @@ -110,7 +110,13 @@ test_that("get_alt_text checks dots", { }) test_that("warnings are thrown for unknown labels", { - p <- ggplot(mtcars, aes(mpg, disp)) + geom_point() + labs(foo = 'bar') + p <- ggplot(mtcars, aes(mpg, disp)) + + geom_point() + + labs( + foo = "i don't exist", + bar = function(x) "i don't exist either", + qux = expression(me * neither) + ) expect_snapshot_warning(ggplot_build(p)) }) From 85c33d37f0da84a406ecdb13f8cc07d0a8329175 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 28 May 2025 15:00:44 +0200 Subject: [PATCH 3/3] approve snapshot of updated test --- tests/testthat/_snaps/labels.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/labels.md b/tests/testthat/_snaps/labels.md index 2a4bd75ff4..dcbcfe974f 100644 --- a/tests/testthat/_snaps/labels.md +++ b/tests/testthat/_snaps/labels.md @@ -15,7 +15,9 @@ # warnings are thrown for unknown labels Ignoring unknown labels: - * `foo = "bar"` + * foo : "i don't exist" + * bar : + * qux : "expression(me * neither)" # plot.tag.position rejects invalid input