@@ -470,6 +470,7 @@ theme <- function(...,
470
470
elements <- find_args(... , complete = NULL , validate = NULL )
471
471
472
472
elements <- fix_theme_deprecations(elements )
473
+ elements <- validate_theme_palettes(elements )
473
474
474
475
# If complete theme set all non-blank elements to inherit from blanks
475
476
if (complete ) {
@@ -562,6 +563,45 @@ fix_theme_deprecations <- function(elements) {
562
563
elements
563
564
}
564
565
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
+
565
605
# ' @export
566
606
# ' @rdname is_tests
567
607
is.theme <- function (x ) inherits(x , " theme" )
0 commit comments