Skip to content

Write out units in full in ggsave error #5091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2022
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
18 changes: 17 additions & 1 deletion R/save.r
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,24 @@ plot_dim <- function(dim = c(NA, NA), scale = 1, units = "in",
}

if (limitsize && any(dim >= 50)) {
units <- switch(
units,
"in" = "inches",
"cm" = "centimeters",
"mm" = "millimeters",
"px" = "pixels"
)
msg <- paste0(
"Dimensions exceed 50 inches ({.arg height} and {.arg width} are ",
"specified in {.emph {units}}"
)
if (units == "pixels") {
msg <- paste0(msg, ").")
} else {
msg <- paste0(msg, " not pixels).")
}
cli::cli_abort(c(
"Dimensions exceed 50 inches ({.arg height} and {.arg width} are specified in {.emph {units}} not pixels).",
msg,
"i" = "If you're sure you want a plot that big, use {.code limitsize = FALSE}.
"), call = call)
}
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-ggsave.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ test_that("uses 7x7 if no graphics device open", {
test_that("warned about large plot unless limitsize = FALSE", {
expect_error(plot_dim(c(50, 50)), "exceed 50 inches")
expect_equal(plot_dim(c(50, 50), limitsize = FALSE), c(50, 50))
expect_error(plot_dim(c(15000, 15000), units = "px"), "in pixels).")
})

test_that("scale multiplies height & width", {
Expand Down