Skip to content

Commit f16f16f

Browse files
authored
enable inheritance for derived theme elements; closes #3549 (#3550)
1 parent 9b667b9 commit f16f16f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

R/theme.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ combine_elements <- function(e1, e2) {
655655
}
656656

657657
# If e1 has any NULL properties, inherit them from e2
658-
n <- vapply(e1[names(e2)], is.null, logical(1))
658+
n <- names(e1)[vapply(e1, is.null, logical(1))]
659659
e1[n] <- e2[n]
660660

661661
# Calculate relative sizes

tests/testthat/test-theme.r

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,29 @@ test_that("calculating theme element inheritance works", {
9999
# Check that a theme_blank in a parent node gets passed along to children
100100
t <- theme_grey() + theme(text = element_blank())
101101
expect_identical(calc_element('axis.title.x', t), element_blank())
102+
103+
# Check that inheritance from derived class works
104+
element_dummyrect <- function(dummy) { # like element_rect but w/ dummy argument
105+
structure(list(
106+
fill = NULL, colour = NULL, dummy = dummy, size = NULL,
107+
linetype = NULL, inherit.blank = FALSE
108+
), class = c("element_dummyrect", "element_rect", "element"))
109+
}
110+
111+
e <- calc_element(
112+
"panel.background",
113+
theme(
114+
rect = element_rect(fill = "white", colour = "black", size = 0.5, linetype = 1),
115+
panel.background = element_dummyrect(dummy = 5))
116+
)
117+
118+
expect_identical(
119+
e,
120+
structure(list(
121+
fill = "white", colour = "black", dummy = 5, size = 0.5, linetype = 1,
122+
inherit.blank = FALSE
123+
), class = c("element_dummyrect", "element_rect", "element"))
124+
)
102125
})
103126

104127
test_that("complete and non-complete themes interact correctly with each other", {

0 commit comments

Comments
 (0)