Skip to content
Merged
Show file tree
Hide file tree
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
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
Loading