Skip to content

Commit 51818fe

Browse files
committed
look for conflicting options
1 parent 1a08f8d commit 51818fe

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

R/theme.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ theme <- function(...,
470470
elements <- find_args(..., complete = NULL, validate = NULL)
471471

472472
elements <- fix_theme_deprecations(elements)
473+
elements <- validate_theme_palettes(elements)
473474

474475
# If complete theme set all non-blank elements to inherit from blanks
475476
if (complete) {
@@ -562,6 +563,45 @@ fix_theme_deprecations <- function(elements) {
562563
elements
563564
}
564565

566+
validate_theme_palettes <- function(elements) {
567+
568+
pals <- c("palette.colour.discrete", "palette.colour.continuous",
569+
"palette.fill.discrete", "palette.fill.continuous",
570+
"palette.color.discrete", "palette.color.continuous")
571+
if (!any(pals %in% names(elements))) {
572+
return(elements)
573+
}
574+
575+
# Standardise spelling
576+
elements <- replace_null(
577+
elements,
578+
palette.colour.discrete = elements$palette.color.discrete,
579+
palette.colour.continuous = elements$palette.color.continuous
580+
)
581+
elements$palette.color.discrete <- NULL
582+
elements$palette.color.continuous <- NULL
583+
584+
# Check for incompatible options
585+
pals <- c("palette.colour.discrete", "palette.colour.continuous",
586+
"palette.fill.discrete", "palette.fill.continuous")
587+
opts <- c("ggplot2.discrete.colour", "ggplot2.continuous.colour",
588+
"ggplot2.discrete.fill", "ggplot2.continuous.fill")
589+
index <- which(pals %in% names(elements))
590+
591+
for (i in index) {
592+
if (is.null(getOption(opts[i]))) {
593+
next
594+
}
595+
cli::cli_warn(c(
596+
"The {.code options('{opts[i]}')} setting is incompatible with the \\
597+
{.arg {pals[i]}} theme setting.",
598+
i = "You can set {.code options({opts[i]} = NULL)}."
599+
))
600+
}
601+
602+
elements
603+
}
604+
565605
#' @export
566606
#' @rdname is_tests
567607
is.theme <- function(x) inherits(x, "theme")

0 commit comments

Comments
 (0)