@@ -522,6 +522,7 @@ Scale <- ggproto("Scale", NULL,
522
522
},
523
523
524
524
update = function (self , params ) {
525
+ check_update_params(self , params )
525
526
inject(self $ new(!!! params ))
526
527
}
527
528
)
@@ -546,6 +547,29 @@ check_breaks_labels <- function(breaks, labels, call = NULL) {
546
547
TRUE
547
548
}
548
549
550
+ check_update_params <- function (scale , params ) {
551
+ if (inherits(scale , " ScaleContinuous" )) {
552
+ args <- fn_fmls_names(continuous_scale )
553
+ } else if (inherits(scale , " ScaleDiscrete" )) {
554
+ args <- fn_fmls_names(discrete_scale )
555
+ } else if (inherits(scale , " ScaleBinned" )) {
556
+ args <- fn_fmls_names(binned_scale )
557
+ } else {
558
+ # We don't know what valid parameters are of custom scale types
559
+ return (invisible (NULL ))
560
+ }
561
+ extra <- setdiff(names(params ), args )
562
+ if (length(extra ) == 0 ) {
563
+ return (invisible (NULL ))
564
+ }
565
+ extra <- paste0(" {.val " , extra , " }" )
566
+ names(extra ) <- rep(" *" , length(extra ))
567
+ cli :: cli_abort(
568
+ c(" Cannot update scale with the unknown {cli::qty(extra)} argument{?s}:" , extra ),
569
+ call = scale $ call
570
+ )
571
+ }
572
+
549
573
default_transform <- function (self , x ) {
550
574
transformation <- self $ get_transformation()
551
575
new_x <- transformation $ transform(x )
@@ -865,6 +889,7 @@ ScaleContinuous <- ggproto("ScaleContinuous", Scale,
865
889
},
866
890
867
891
update = function (self , params ) {
892
+ check_update_params(self , params )
868
893
# We may need to update limits when previously transformed and
869
894
# a new transformation is coming in
870
895
if (" transform" %in% names(params ) &&
0 commit comments