Skip to content

Commit 2e649bb

Browse files
authored
Add type check to theme_set() (#5252)
* Add type check to `theme_set()` * Include test snapshot
1 parent e0efd7b commit 2e649bb

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

R/theme-current.R

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ theme_get <- function() {
9090
#' @param new new theme (a list of theme elements)
9191
#' @export
9292
theme_set <- function(new) {
93+
check_object(new, is.theme, "a {.cls theme} object")
9394
old <- ggplot_global$theme_current
9495
ggplot_global$theme_current <- new
9596
invisible(old)

tests/testthat/_snaps/theme.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
Theme element `test` has "NULL" property without default: fill, colour, linewidth, and linetype
2222

23+
---
24+
25+
`new` must be a <theme> object, not the string "foo".
26+
2327
# element tree can be modified
2428

2529
The `blablabla` theme element is not defined in the element hierarchy.

tests/testthat/test-theme.R

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ test_that("incorrect theme specifications throw meaningful errors", {
264264
expect_snapshot_error(calc_element("line", theme(line = element_rect())))
265265
register_theme_elements(element_tree = list(test = el_def("element_rect")))
266266
expect_snapshot_error(calc_element("test", theme_gray() + theme(test = element_rect())))
267+
expect_snapshot_error(theme_set("foo"))
267268
})
268269

269270
test_that("element tree can be modified", {

0 commit comments

Comments
 (0)