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