Skip to content

Commit 43a05da

Browse files
committed
set_theme() resets theme if called with no arguments. Also added a simple test.
1 parent 961b194 commit 43a05da

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

R/theme-current.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ 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
9696
set_theme <- function(new) {
97+
if (missing(new)) {
98+
new <- ggplot_global$theme_default
99+
}
97100
check_object(new, is_theme, "a {.cls theme} object")
98101
old <- ggplot_global$theme_current
99102
ggplot_global$theme_current <- new
@@ -141,4 +144,3 @@ theme_replace <- replace_theme
141144

142145
e1
143146
}
144-

man/get_theme.Rd

Lines changed: 1 addition & 1 deletion
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)