diff --git a/NAMESPACE b/NAMESPACE index 717abb2e18..8362f037d4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ S3method("$",ggproto) S3method("$",ggproto_parent) +S3method("$",theme) S3method("$<-",uneval) S3method("+",gg) S3method("[",mapped_discrete) diff --git a/R/theme.R b/R/theme.R index e07fd29214..1774a23e08 100644 --- a/R/theme.R +++ b/R/theme.R @@ -804,5 +804,10 @@ is.subclass <- function(x, y) { #' @keywords internal is.theme <- function(x) inherits(x, "theme") +#' @export +`$.theme` <- function(x, ...) { + .subset2(x, ...) +} + #' @export print.theme <- function(x, ...) utils::str(x) diff --git a/tests/testthat/test-theme.R b/tests/testthat/test-theme.R index 10773ab176..ab54bf9764 100644 --- a/tests/testthat/test-theme.R +++ b/tests/testthat/test-theme.R @@ -1,5 +1,11 @@ skip_on_cran() # This test suite is long-running (on cran) and is skipped +test_that("dollar subsetting the theme does no partial matching", { + t <- theme(foobar = 12) + expect_null(t$foo) + expect_equal(t$foobar, 12) +}) + test_that("modifying theme element properties with + operator works", { # Changing a "leaf node" works