Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions R/theme-current.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ get_theme <- function() {
theme_get <- get_theme

#' @rdname get_theme
#' @param new new theme (a list of theme elements)
#' @param new new theme (a list of theme elements). Sets theme to the default (theme_grey) if `new` isn't supplied.
#' @export
set_theme <- function(new) {
if (missing(new)) {
new <- ggplot_global$theme_default
}
check_object(new, is_theme, "a {.cls theme} object")
old <- ggplot_global$theme_current
ggplot_global$theme_current <- new
Expand Down Expand Up @@ -141,4 +144,3 @@ theme_replace <- replace_theme

e1
}

2 changes: 1 addition & 1 deletion man/get_theme.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-theme.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ test_that("modifying theme element properties with + operator works", {
)
})

test_that("set_theme() resets theme to default when called with no arguments", {
theme_set(theme_void())
set_theme()
expect_identical(theme_get(), theme_grey())
})

test_that("adding theme object to ggplot object with + operator works", {
## test with complete theme
p <- ggplot(data.frame(x = 1:3), aes(x, x)) + geom_point() + theme_grey()
Expand Down
Loading