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, 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