@@ -866,15 +866,21 @@ calc_element <- function(element, theme, verbose = FALSE, skip_blank = FALSE,
866
866
# ' # Adopt size but ignore colour
867
867
# ' merge_element(new, old)
868
868
# '
869
- merge_element <- S7 :: new_generic(" merge_element" , c(" new" , " old" ))
869
+ merge_element <- S7 :: new_generic(
870
+ " merge_element" , dispatch_args = c(" new" , " old" ),
871
+ fun = function (new , old , ... ) {
872
+ # If old is NULL or element_blank, then just return new
873
+ if (is.null(old ) || is_theme_element(old , " blank" )) {
874
+ return (new )
875
+ }
876
+ S7 :: S7_dispatch()
877
+ }
878
+ )
870
879
871
880
S7 :: method(merge_element , list (S7 :: class_any , S7 :: class_any )) <-
872
881
function (new , old , ... ) {
873
- if (is.null(old ) || is_theme_element(old , " blank" )) {
874
- # If old is NULL or element_blank, then just return new
875
- return (new )
876
- } else if (is.null(new ) || is.character(new ) || is.numeric(new ) || is.unit(new ) ||
877
- is.logical(new ) || is.function(new )) {
882
+ if (is.null(new ) || is.character(new ) || is.numeric(new ) || is.unit(new ) ||
883
+ is.logical(new ) || is.function(new )) {
878
884
# If new is NULL, or a string, numeric vector, unit, or logical, just return it
879
885
return (new )
880
886
}
@@ -891,11 +897,6 @@ S7::method(merge_element, list(element_blank, S7::class_any)) <-
891
897
892
898
S7 :: method(merge_element , list (element , S7 :: class_any )) <-
893
899
function (new , old , ... ) {
894
- if (is.null(old ) || is_theme_element(old , " blank" )) {
895
- # If old is NULL or element_blank, then just return new
896
- return (new )
897
- }
898
-
899
900
# actual merging can only happen if classes match
900
901
if (! inherits(new , class(old )[1 ])) {
901
902
cli :: cli_abort(" Only elements of the same class can be merged." )
@@ -915,9 +916,6 @@ S7::method(merge_element, list(element, S7::class_any)) <-
915
916
916
917
S7 :: method(merge_element , list (margin , S7 :: class_any )) <-
917
918
function (new , old , ... ) {
918
- if (is.null(old ) || is_theme_element(old , " blank" )) {
919
- return (new )
920
- }
921
919
if (anyNA(new )) {
922
920
new [is.na(new )] <- old [is.na(new )]
923
921
}
@@ -928,9 +926,6 @@ S7::method(merge_element, list(margin, S7::class_any)) <-
928
926
# TODO: in subsequent release cycle, start deprecation
929
927
S7 :: method(merge_element , list (S7 :: new_S3_class(" element" ), S7 :: class_any )) <-
930
928
function (new , old , ... ) {
931
- if (is.null(old ) || is_theme_element(old , " blank" )) {
932
- return (new )
933
- }
934
929
if (S7 :: S7_inherits(old )) {
935
930
old <- S7 :: props(old )
936
931
}
0 commit comments