Skip to content

Commit b38f3e5

Browse files
committed
fallback for register_theme_elements()
1 parent a775635 commit b38f3e5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

R/theme-elements.R

+21
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,27 @@ check_element_tree <- function(x, arg = caller_arg(x), call = caller_env()) {
692692
#' @keywords internal
693693
#' @export
694694
el_def <- function(class = NULL, inherit = NULL, description = NULL) {
695+
if (is.character(class) && length(class) == 1) {
696+
# Swap S3 class name for S7 class object
697+
class <- switch(
698+
class,
699+
element = element,
700+
element_blank = element_blank,
701+
element_rect = element_rect,
702+
element_line = element_line,
703+
element_text = element_text,
704+
element_polygon = element_polygon,
705+
element_point = element_point,
706+
element_geom = element_geom,
707+
margin = margin,
708+
class
709+
)
710+
}
711+
# margins often occur in c("unit", "margin", "rel"), we cannot use the
712+
# S7 class here because we don't support heterogeneous lists
713+
if (is.character(class) && length(class) > 1) {
714+
class[class == "margin"] <- "ggplot2::margin"
715+
}
695716
list(class = class, inherit = inherit, description = description)
696717
}
697718

0 commit comments

Comments
 (0)