@@ -866,15 +866,21 @@ calc_element <- function(element, theme, verbose = FALSE, skip_blank = FALSE,
866866# ' # Adopt size but ignore colour
867867# ' merge_element(new, old)
868868# '
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+ )
870879
871880S7 :: method(merge_element , list (S7 :: class_any , S7 :: class_any )) <-
872881 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 )) {
878884 # If new is NULL, or a string, numeric vector, unit, or logical, just return it
879885 return (new )
880886 }
@@ -891,11 +897,6 @@ S7::method(merge_element, list(element_blank, S7::class_any)) <-
891897
892898S7 :: method(merge_element , list (element , S7 :: class_any )) <-
893899 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-
899900 # actual merging can only happen if classes match
900901 if (! inherits(new , class(old )[1 ])) {
901902 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)) <-
915916
916917S7 :: method(merge_element , list (margin , S7 :: class_any )) <-
917918 function (new , old , ... ) {
918- if (is.null(old ) || is_theme_element(old , " blank" )) {
919- return (new )
920- }
921919 if (anyNA(new )) {
922920 new [is.na(new )] <- old [is.na(new )]
923921 }
@@ -928,9 +926,6 @@ S7::method(merge_element, list(margin, S7::class_any)) <-
928926# TODO: in subsequent release cycle, start deprecation
929927S7 :: method(merge_element , list (S7 :: new_S3_class(" element" ), S7 :: class_any )) <-
930928 function (new , old , ... ) {
931- if (is.null(old ) || is_theme_element(old , " blank" )) {
932- return (new )
933- }
934929 if (S7 :: S7_inherits(old )) {
935930 old <- S7 :: props(old )
936931 }
0 commit comments