Skip to content

Commit 61f9a0a

Browse files
authored
Only throw scale training errors when the Range class is the expected one (#5649)
1 parent d5c2f1f commit 61f9a0a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

R/scale-.R

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,15 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
635635
}
636636
# Intercept error here to give examples and mention scale in call
637637
if (is.factor(x) || !typeof(x) %in% c("integer", "double")) {
638-
cli::cli_abort(
639-
c("Discrete values supplied to continuous scale.",
640-
i = "Example values: {.and {.val {head(x, 5)}}}"),
641-
call = self$call
642-
)
638+
# These assumptions only hold for standard ContinuousRange class, so
639+
# we skip the error if another range class is used
640+
if (inherits(self$range, "ContinuousRange")) {
641+
cli::cli_abort(
642+
c("Discrete values supplied to continuous scale.",
643+
i = "Example values: {.and {.val {head(x, 5)}}}"),
644+
call = self$call
645+
)
646+
}
643647
}
644648
self$range$train(x)
645649
},
@@ -909,11 +913,15 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
909913
}
910914
# Intercept error here to give examples and mention scale in call
911915
if (!is.discrete(x)) {
912-
cli::cli_abort(
913-
c("Continuous values supplied to discrete scale.",
914-
i = "Example values: {.and {.val {head(x, 5)}}}"),
915-
call = self$call
916-
)
916+
# These assumptions only hold for standard DiscreteRange class, so
917+
# we skip the error if another range class is used
918+
if (inherits(self$range, "DiscreteRange")) {
919+
cli::cli_abort(
920+
c("Continuous values supplied to discrete scale.",
921+
i = "Example values: {.and {.val {head(x, 5)}}}"),
922+
call = self$call
923+
)
924+
}
917925
}
918926
self$range$train(x, drop = self$drop, na.rm = !self$na.translate)
919927
},

0 commit comments

Comments
 (0)