diff --git a/R/plot-build.R b/R/plot-build.R index 1bf0019324..2c1695e350 100644 --- a/R/plot-build.R +++ b/R/plot-build.R @@ -276,14 +276,19 @@ ggplot_gtable.ggplot_built <- function(data) { # positioning of caption is governed by plot.caption.position # "panel" means align to the panel(s) # "plot" means align to the entire plot (except margins and tag) - title_pos <- theme$plot.title.position %||% "panel" - if (!(title_pos %in% c("panel", "plot"))) { - cli::cli_abort('{.var plot.title.position} should be either {.val "panel"} or {.val "plot"}.') - } - caption_pos <- theme$plot.caption.position %||% "panel" - if (!(caption_pos %in% c("panel", "plot"))) { - cli::cli_abort('{.var plot.caption.position} should be either {.val "panel"} or {.val "plot"}.') - } + title_pos <- arg_match0( + theme$plot.title.position %||% "panel", + c("panel", "plot"), + arg_nm = "plot.title.position", + error_call = expr(theme()) + ) + + caption_pos <- arg_match0( + theme$plot.caption.position %||% "panel", + values = c("panel", "plot"), + arg_nm = "plot.caption.position", + error_call = expr(theme()) + ) pans <- plot_table$layout[grepl("^panel", plot_table$layout$name), , drop = FALSE] if (title_pos == "panel") { diff --git a/tests/testthat/_snaps/theme.md b/tests/testthat/_snaps/theme.md index b879a97d01..b0f60cd35a 100644 --- a/tests/testthat/_snaps/theme.md +++ b/tests/testthat/_snaps/theme.md @@ -42,11 +42,11 @@ # Theme elements are checked during build - `plot.title.position` should be either "\"panel\"" or "\"plot\"". + `plot.title.position` must be one of "panel" or "plot", not "test". --- - `plot.caption.position` should be either "\"panel\"" or "\"plot\"". + `plot.caption.position` must be one of "panel" or "plot", not "test". --- diff --git a/tests/testthat/test-stat-summary.R b/tests/testthat/test-stat-summary.R index 5f8cc4b4fd..925ba8d4b1 100644 --- a/tests/testthat/test-stat-summary.R +++ b/tests/testthat/test-stat-summary.R @@ -68,6 +68,7 @@ test_that("stat_summary_(2d|hex) work with lambda expressions", { # stat_summary_hex # this plot is a bit funky, but easy to reason through + skip_if_not_installed("hexbin") p1 <- ggplot(dat, aes(x, y, z = z)) + stat_summary_hex(fun = function(x) mean(x))