File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -612,21 +612,31 @@ merge_element.element <- function(new, old) {
612
612
new
613
613
}
614
614
615
- # Combine the properties of two elements
616
- #
617
- # @param e1 An element object
618
- # @param e2 An element object which e1 inherits from
615
+ # ' Combine the properties of two elements
616
+ # '
617
+ # ' @param e1 An element object
618
+ # ' @param e2 An element object from which e1 inherits
619
+ # '
620
+ # ' @noRd
621
+ # '
619
622
combine_elements <- function (e1 , e2 ) {
620
623
621
624
# If e2 is NULL, nothing to inherit
622
625
if (is.null(e2 ) || inherits(e1 , " element_blank" )) return (e1 )
626
+
623
627
# If e1 is NULL inherit everything from e2
624
628
if (is.null(e1 )) return (e2 )
629
+
630
+ # If neither of e1 or e2 are element_* objects, return e1
631
+ if (! inherits(e1 , " element" ) && ! inherits(e2 , " element" )) return (e1 )
632
+
625
633
# If e2 is element_blank, and e1 inherits blank inherit everything from e2,
626
634
# otherwise ignore e2
627
635
if (inherits(e2 , " element_blank" )) {
628
- if (e1 $ inherit.blank ) return (e2 )
629
- else return (e1 )
636
+ if (e1 $ inherit.blank )
637
+ return (e2 )
638
+ else
639
+ return (e1 )
630
640
}
631
641
632
642
# If e1 has any NULL properties, inherit them from e2
Original file line number Diff line number Diff line change @@ -213,6 +213,12 @@ test_that("elements can be merged", {
213
213
)
214
214
})
215
215
216
+ test_that(" theme elements that don't inherit from element can be combined" , {
217
+ expect_identical(combine_elements(1 , NULL ), 1 )
218
+ expect_identical(combine_elements(NULL , 1 ), 1 )
219
+ expect_identical(combine_elements(1 , 0 ), 1 )
220
+ })
221
+
216
222
test_that(" complete plot themes shouldn't inherit from default" , {
217
223
default_theme <- theme_gray() + theme(axis.text.x = element_text(colour = " red" ))
218
224
base <- qplot(1 , 1 )
You can’t perform that action at this time.
0 commit comments