diff --git a/R/save.r b/R/save.r index 2d397bf04b..c85d99be97 100644 --- a/R/save.r +++ b/R/save.r @@ -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) } diff --git a/tests/testthat/test-ggsave.R b/tests/testthat/test-ggsave.R index 43d7a8f455..1921bd9769 100644 --- a/tests/testthat/test-ggsave.R +++ b/tests/testthat/test-ggsave.R @@ -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", {