Skip to content

Commit 1a08f8d

Browse files
committed
isolate deprecated theme elements in function
1 parent 1bfb3c9 commit 1a08f8d

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

R/theme.R

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,26 @@ theme <- function(...,
469469
validate = TRUE) {
470470
elements <- find_args(..., complete = NULL, validate = NULL)
471471

472+
elements <- fix_theme_deprecations(elements)
473+
474+
# If complete theme set all non-blank elements to inherit from blanks
475+
if (complete) {
476+
elements <- lapply(elements, function(el) {
477+
if (is.theme_element(el) && !inherits(el, "element_blank")) {
478+
el$inherit.blank <- TRUE
479+
}
480+
el
481+
})
482+
}
483+
structure(
484+
elements,
485+
class = c("theme", "gg"),
486+
complete = complete,
487+
validate = validate
488+
)
489+
}
490+
491+
fix_theme_deprecations <- function(elements) {
472492
if (!is.null(elements$axis.ticks.margin)) {
473493
deprecate_warn0(
474494
"2.0.0", "theme(axis.ticks.margin)",
@@ -539,22 +559,7 @@ theme <- function(...,
539559
elements$legend.position.inside <- elements$legend.position
540560
elements$legend.position <- "inside"
541561
}
542-
543-
# If complete theme set all non-blank elements to inherit from blanks
544-
if (complete) {
545-
elements <- lapply(elements, function(el) {
546-
if (is.theme_element(el) && !inherits(el, "element_blank")) {
547-
el$inherit.blank <- TRUE
548-
}
549-
el
550-
})
551-
}
552-
structure(
553-
elements,
554-
class = c("theme", "gg"),
555-
complete = complete,
556-
validate = validate
557-
)
562+
elements
558563
}
559564

560565
#' @export

0 commit comments

Comments
 (0)