Skip to content

Commit

Permalink
Fix regression from #6027 (#6098)
Browse files Browse the repository at this point in the history
* fallback for numeric expand

* add test
  • Loading branch information
teunbrand authored Sep 23, 2024
1 parent f87ea34 commit 7f6d5bf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/coord-.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ render_axis <- function(panel_params, axis, scale, position, theme) {

# Elaborates an 'expand' argument for every side (top, right, bottom or left)
parse_coord_expand <- function(expand) {
if (is.numeric(expand) && all(expand %in% c(0, 1))) {
expand <- as.logical(expand)
}
check_logical(expand)
if (anyNA(expand)) {
cli::cli_abort("{.arg expand} cannot contain missing values.")
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-coord-.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ test_that("coords append a column to the layout correctly", {
expect_equal(test$COORD, c(1, 2, 1))
})

test_that("parse_coord_expand parses correctly", {

p <- parse_coord_expand(FALSE)
expect_equal(p, rep(FALSE, 4))

p <- parse_coord_expand(c(FALSE, TRUE))
expect_equal(p, c(FALSE, TRUE, FALSE, TRUE))

p <- parse_coord_expand(c(top = FALSE, left = FALSE))
expect_equal(p, c(FALSE, TRUE, TRUE, FALSE))

# Dependencies might use `expand = 1`
p <- parse_coord_expand(c(1, 0))
expect_equal(p, c(TRUE, FALSE, TRUE, FALSE))

})

test_that("coord expand takes a vector", {

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

0 comments on commit 7f6d5bf

Please sign in to comment.