Skip to content

Commit eece200

Browse files
authored
set_theme() resets theme if called with no arguments. (#6629)
Fixes #6598
1 parent 2e5fcbb commit eece200

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

R/theme-current.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ get_theme <- function() {
9191
theme_get <- get_theme
9292

9393
#' @rdname get_theme
94-
#' @param new new theme (a list of theme elements)
94+
#' @param new new theme (a list of theme elements). Sets theme to the default ([theme_grey()]) if `new` isn't supplied.
9595
#' @export
96-
set_theme <- function(new) {
96+
set_theme <- function(new = NULL) {
97+
new <- new %||% ggplot_global$theme_default
9798
check_object(new, is_theme, "a {.cls theme} object")
9899
old <- ggplot_global$theme_current
99100
ggplot_global$theme_current <- new
@@ -141,4 +142,3 @@ theme_replace <- replace_theme
141142

142143
e1
143144
}
144-

man/get_theme.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-theme.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ test_that("modifying theme element properties with + operator works", {
5656
)
5757
})
5858

59+
test_that("set_theme() resets theme to default when called with no arguments", {
60+
theme_set(theme_void())
61+
set_theme()
62+
expect_identical(theme_get(), theme_grey())
63+
})
64+
5965
test_that("adding theme object to ggplot object with + operator works", {
6066
## test with complete theme
6167
p <- ggplot(data.frame(x = 1:3), aes(x, x)) + geom_point() + theme_grey()

0 commit comments

Comments
 (0)