From e2b64cef5a22419aee12a28ecec72aa10d55166c Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Sep 2024 12:52:16 +0200 Subject: [PATCH 1/2] fallback for numeric expand --- R/coord-.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/coord-.R b/R/coord-.R index 0d0bb5ecb9..11f498c9b8 100644 --- a/R/coord-.R +++ b/R/coord-.R @@ -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.") From 31277eab9a3aeeeacb572e70fc2cded0f34c15d7 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Mon, 23 Sep 2024 09:30:19 +0200 Subject: [PATCH 2/2] add test --- tests/testthat/test-coord-.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/testthat/test-coord-.R b/tests/testthat/test-coord-.R index 6a50369bbc..f1e910c807 100644 --- a/tests/testthat/test-coord-.R +++ b/tests/testthat/test-coord-.R @@ -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))