Skip to content

Commit 5f518d0

Browse files
teunbrandthomasp85
andauthored
No partial matching in theme subsetting (#5522)
* Add dollar subsetting for themes * add test * Update R/theme.R Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com> --------- Co-authored-by: Thomas Lin Pedersen <thomasp85@gmail.com>
1 parent 44c2497 commit 5f518d0

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
S3method("$",ggproto)
44
S3method("$",ggproto_parent)
5+
S3method("$",theme)
56
S3method("$<-",uneval)
67
S3method("+",gg)
78
S3method("[",mapped_discrete)

R/theme.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,5 +804,10 @@ is.subclass <- function(x, y) {
804804
#' @keywords internal
805805
is.theme <- function(x) inherits(x, "theme")
806806

807+
#' @export
808+
`$.theme` <- function(x, ...) {
809+
.subset2(x, ...)
810+
}
811+
807812
#' @export
808813
print.theme <- function(x, ...) utils::str(x)

tests/testthat/test-theme.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
skip_on_cran() # This test suite is long-running (on cran) and is skipped
22

3+
test_that("dollar subsetting the theme does no partial matching", {
4+
t <- theme(foobar = 12)
5+
expect_null(t$foo)
6+
expect_equal(t$foobar, 12)
7+
})
8+
39
test_that("modifying theme element properties with + operator works", {
410

511
# Changing a "leaf node" works

0 commit comments

Comments
 (0)