Skip to content

Commit fda764c

Browse files
authored
Merge pull request #385 from stan-dev/fix-theme-2
Set theme in .onLoad to avoid issue with ggplot2 v4.0
2 parents 633addd + 4ef0a82 commit fda764c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

R/zzz.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
"\nUse update.packages('ggplot2') to update.")
1111
}
1212
}
13+
.onLoad <- function(libname, pkgname) {
14+
bayesplot_theme_set()
15+
}

tests/testthat/test-aesthetics.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,18 @@ test_that("ggplot2::theme_set overrides bayesplot theme", {
210210
expect_identical(bayesplot_theme_get(), minimal)
211211
})
212212

213+
test_that(".onLoad keeps ggplot theme and resets bayesplot theme", {
214+
old <- ggplot2::theme_set(ggplot2::theme_minimal())
215+
before <- ggplot2::theme_get()
216+
bayesplot:::.onLoad()
217+
218+
expect_identical(bayesplot_theme_get(), default)
219+
expect_equal(.bayesplot_theme_env$current, default)
220+
expect_equal(ggplot2::theme_get(), before)
221+
expect_equal(.bayesplot_theme_env$gg_current, before)
222+
ggplot2::theme_set(old)
223+
})
224+
213225
bayesplot_theme_set(bayesplot::theme_default())
214226
color_scheme_set()
215227

0 commit comments

Comments
 (0)