Skip to content

Commit 7f6d5bf

Browse files
authored
Fix regression from #6027 (#6098)
* fallback for numeric expand * add test
1 parent f87ea34 commit 7f6d5bf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

R/coord-.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ render_axis <- function(panel_params, axis, scale, position, theme) {
246246

247247
# Elaborates an 'expand' argument for every side (top, right, bottom or left)
248248
parse_coord_expand <- function(expand) {
249+
if (is.numeric(expand) && all(expand %in% c(0, 1))) {
250+
expand <- as.logical(expand)
251+
}
249252
check_logical(expand)
250253
if (anyNA(expand)) {
251254
cli::cli_abort("{.arg expand} cannot contain missing values.")

tests/testthat/test-coord-.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ test_that("coords append a column to the layout correctly", {
7575
expect_equal(test$COORD, c(1, 2, 1))
7676
})
7777

78+
test_that("parse_coord_expand parses correctly", {
79+
80+
p <- parse_coord_expand(FALSE)
81+
expect_equal(p, rep(FALSE, 4))
82+
83+
p <- parse_coord_expand(c(FALSE, TRUE))
84+
expect_equal(p, c(FALSE, TRUE, FALSE, TRUE))
85+
86+
p <- parse_coord_expand(c(top = FALSE, left = FALSE))
87+
expect_equal(p, c(FALSE, TRUE, TRUE, FALSE))
88+
89+
# Dependencies might use `expand = 1`
90+
p <- parse_coord_expand(c(1, 0))
91+
expect_equal(p, c(TRUE, FALSE, TRUE, FALSE))
92+
93+
})
94+
7895
test_that("coord expand takes a vector", {
7996

8097
base <- ggplot() + lims(x = c(0, 10), y = c(0, 10))

0 commit comments

Comments
 (0)