From f625c025117951297a0a3d3a53efbd20fd76ac25 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 30 Apr 2025 11:32:49 +0200 Subject: [PATCH 1/2] pass on calls --- R/scale-.R | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/R/scale-.R b/R/scale-.R index fa37bf5571..5e80a833a8 100644 --- a/R/scale-.R +++ b/R/scale-.R @@ -684,19 +684,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale, if (length(x) == 0) { return() } - # Intercept error here to give examples and mention scale in call - if (is.factor(x) || !typeof(x) %in% c("integer", "double")) { - # These assumptions only hold for standard ContinuousRange class, so - # we skip the error if another range class is used - if (inherits(self$range, "ContinuousRange")) { - cli::cli_abort( - c("Discrete values supplied to continuous scale.", - i = "Example values: {.and {.val {head(x, 5)}}}"), - call = self$call - ) - } - } - self$range$train(x) + self$range$train(x, call = self$call) }, is_empty = function(self) { @@ -964,19 +952,12 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale, if (length(x) == 0) { return() } - # Intercept error here to give examples and mention scale in call - if (!is.discrete(x)) { - # These assumptions only hold for standard DiscreteRange class, so - # we skip the error if another range class is used - if (inherits(self$range, "DiscreteRange")) { - cli::cli_abort( - c("Continuous values supplied to discrete scale.", - i = "Example values: {.and {.val {head(x, 5)}}}"), - call = self$call - ) - } - } - self$range$train(x, drop = self$drop, na.rm = !self$na.translate) + self$range$train( + x, + drop = self$drop, + na.rm = !self$na.translate, + call = self$call + ) }, transform = identity, @@ -1196,17 +1177,16 @@ ScaleBinned <- ggproto("ScaleBinned", Scale, is_discrete = function() FALSE, train = function(self, x) { + if (length(x) == 0) { + return() + } if (!is.numeric(x)) { cli::cli_abort( "Binned scales only support continuous data.", call = self$call ) } - - if (length(x) == 0) { - return() - } - self$range$train(x) + self$range$train(x, call = self$call) }, transform = default_transform, From 1223ee24d93565d3c3982e2d4c1eb72e64765e70 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 30 Apr 2025 11:35:38 +0200 Subject: [PATCH 2/2] accept snapshot --- tests/testthat/_snaps/scales.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/_snaps/scales.md b/tests/testthat/_snaps/scales.md index 33b36a3cd8..3d7cf53e7c 100644 --- a/tests/testthat/_snaps/scales.md +++ b/tests/testthat/_snaps/scales.md @@ -198,13 +198,13 @@ # training incorrectly appropriately communicates the offenders - Continuous values supplied to discrete scale. - i Example values: 1, 2, 3, 4, and 5 + Continuous value supplied to a discrete scale. + i Example values: 1, 2, 3, 4, and 5. --- - Discrete values supplied to continuous scale. - i Example values: "A", "B", "C", "D", and "E" + Discrete value supplied to a continuous scale. + i Example values: "A" and "E". # Using `scale_name` prompts deprecation message