@@ -948,21 +948,36 @@ check_element <- function(el, elname, element_tree, call = caller_env()) {
948
948
949
949
# NULL values for elements are OK
950
950
if (is.null(el )) return ()
951
+
951
952
class <- eldef $ class
952
- if (inherits(class , " S7_class" ) && S7 :: S7_inherits(el )) {
953
- if (S7 :: S7_inherits(el , class ) || is_theme_element(el , " blank" )) {
953
+ if (inherits(class , " S7_class" )) {
954
+ inherit_ok <- S7 :: S7_inherits(el , class )
955
+ } else {
956
+ inherit_ok <- inherits(el , class )
957
+ }
958
+
959
+ if (is.character(class ) && any(c(" margin" , " ggplot2::margin" ) %in% class )) {
960
+ if (" rel" %in% class && is.rel(el )) {
954
961
return ()
955
962
}
963
+ if (is.unit(el ) && length(el ) == 4 ) {
964
+ return ()
965
+ }
966
+ cli :: cli_abort(
967
+ " The {.var {elname}} theme element must be a {.cls unit} vector of length 4" ,
968
+ call = call
969
+ )
956
970
}
957
971
958
- if (is.character(class ) && " margin" %in% class ) {
959
- if (! is.unit(el ) && length(el ) == 4 )
960
- cli :: cli_abort(" The {.var {elname}} theme element must be a {.cls unit} vector of length 4." , call = call )
961
- } else if (! inherits(el , class ) && ! is_theme_element(el , " blank" )) {
962
- if (inherits(class , " S7_class" )) {
963
- class <- class @ name
964
- }
965
- cli :: cli_abort(" The {.var {elname}} theme element must be a {.cls {class}} object." , call = call )
972
+ # Maybe we should check that `class` is an element class before approving of
973
+ # blank elements?
974
+ if (inherit_ok || is_theme_element(el , " blank" )) {
975
+ return ()
966
976
}
967
- invisible ()
977
+
978
+ class_name <- if (inherits(class , " S7_class" )) class @ name else class
979
+ cli :: cli_abort(
980
+ " The {.var {elname}} theme element must be a {.cls {class_name}} object." ,
981
+ call = call
982
+ )
968
983
}
0 commit comments