Skip to content

Commit 5dd6c2a

Browse files
committed
Fix calc_element for character/numeric input
1 parent 882584f commit 5dd6c2a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

R/theme.r

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,16 @@ calc_element <- function(element, theme, verbose = FALSE, skip_blank = FALSE,
565565
# it is of the class specified in element_tree
566566
if (!is.null(el_out) &&
567567
!inherits(el_out, element_tree[[element]]$class)) {
568-
cli::cli_abort("Theme element {.var {element}} must have class {.cls {ggplot_global$element_tree[[element]]$class}}", call = call)
568+
msg <- "Theme element {.var {element}} must have class {.cls {ggplot_global$element_tree[[element]]$class}}"
569+
570+
# 'character' is keyword that may also mean 'numeric', see ?el_def
571+
if (element_tree[[element]]$class == "character") {
572+
if (!is.numeric(el_out)) {
573+
cli::cli_abort(msg, call = call)
574+
}
575+
} else {
576+
cli::cli_abort(msg, call = call)
577+
}
569578
}
570579

571580
# Get the names of parents from the inheritance tree

0 commit comments

Comments
 (0)