Skip to content

Be more conservative in throwing scale training error #5649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions R/scale-.R
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,15 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
}
# Intercept error here to give examples and mention scale in call
if (is.factor(x) || !typeof(x) %in% c("integer", "double")) {
cli::cli_abort(
c("Discrete values supplied to continuous scale.",
i = "Example values: {.and {.val {head(x, 5)}}}"),
call = self$call
)
# 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)
},
Expand Down Expand Up @@ -913,11 +917,15 @@ ScaleDiscrete <- ggproto("ScaleDiscrete", Scale,
}
# Intercept error here to give examples and mention scale in call
if (!is.discrete(x)) {
cli::cli_abort(
c("Continuous values supplied to discrete scale.",
i = "Example values: {.and {.val {head(x, 5)}}}"),
call = self$call
)
# 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)
},
Expand Down