Skip to content

Commit d37e8dc

Browse files
committed
add check_continuous_limits()
1 parent 6bee559 commit d37e8dc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

R/scale-.R

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
128128
}
129129

130130
transform <- as.transform(transform)
131+
limits <- allow_lambda(limits)
132+
131133
if (!is.null(limits) && !is.function(limits)) {
132134
limits <- transform$transform(limits)
133135
}
136+
check_continuous_limits(limits, call = call)
134137

135138
# Convert formula to function if appropriate
136-
limits <- allow_lambda(limits)
137139
breaks <- allow_lambda(breaks)
138140
labels <- allow_lambda(labels)
139141
rescaler <- allow_lambda(rescaler)
@@ -1402,6 +1404,16 @@ check_transformation <- function(x, transformed, name, arg = NULL, call = NULL)
14021404
cli::cli_warn(msg, call = call)
14031405
}
14041406

1407+
check_continuous_limits <- function(limits, ...,
1408+
arg = caller_arg(limits),
1409+
call = caller_env()) {
1410+
if (is.null(limits) || is.function(limits)) {
1411+
return(invisible())
1412+
}
1413+
check_numeric(limits, arg = arg, call = call, allow_na = TRUE)
1414+
check_length(limits, 2L, arg = arg, call = call)
1415+
}
1416+
14051417
trans_support_nbreaks <- function(trans) {
14061418
"n" %in% names(formals(trans$breaks))
14071419
}

tests/testthat/test-scales-breaks-labels.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ test_that("out-of-range breaks are dropped", {
7979

8080
test_that("no minor breaks when only one break", {
8181
sc1 <- scale_x_discrete(limits = "a")
82-
sc2 <- scale_x_continuous(limits = 1)
82+
sc2 <- scale_x_continuous(limits = c(1, 1))
8383

8484
expect_length(sc1$get_breaks_minor(), 0)
8585
expect_length(sc2$get_breaks_minor(), 0)

0 commit comments

Comments
 (0)