diff --git a/R/theme-current.R b/R/theme-current.R index 396b53e95b..b56b2e1651 100644 --- a/R/theme-current.R +++ b/R/theme-current.R @@ -90,6 +90,7 @@ theme_get <- function() { #' @param new new theme (a list of theme elements) #' @export theme_set <- function(new) { + check_object(new, is.theme, "a {.cls theme} object") old <- ggplot_global$theme_current ggplot_global$theme_current <- new invisible(old) diff --git a/tests/testthat/_snaps/theme.md b/tests/testthat/_snaps/theme.md index 6fd9ed6eb3..0fe584926a 100644 --- a/tests/testthat/_snaps/theme.md +++ b/tests/testthat/_snaps/theme.md @@ -20,6 +20,10 @@ Theme element `test` has "NULL" property without default: fill, colour, linewidth, and linetype +--- + + `new` must be a object, not the string "foo". + # element tree can be modified The `blablabla` theme element is not defined in the element hierarchy. diff --git a/tests/testthat/test-theme.R b/tests/testthat/test-theme.R index 3d64894b15..5ec9792457 100644 --- a/tests/testthat/test-theme.R +++ b/tests/testthat/test-theme.R @@ -264,6 +264,7 @@ test_that("incorrect theme specifications throw meaningful errors", { expect_snapshot_error(calc_element("line", theme(line = element_rect()))) register_theme_elements(element_tree = list(test = el_def("element_rect"))) expect_snapshot_error(calc_element("test", theme_gray() + theme(test = element_rect()))) + expect_snapshot_error(theme_set("foo")) }) test_that("element tree can be modified", {