@@ -107,6 +107,7 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
107
107
oob = censor , expand = waiver(), na.value = NA ,
108
108
transform = " identity" , trans = deprecated(),
109
109
guide = " legend" , position = " left" ,
110
+ fallback.palette = NULL ,
110
111
call = caller_call(),
111
112
super = ScaleContinuous ) {
112
113
call <- call %|| % current_call()
@@ -121,6 +122,7 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
121
122
aesthetics <- standardise_aes_names(aesthetics )
122
123
123
124
check_breaks_labels(breaks , labels , call = call )
125
+ check_fallback_palette(palette , fallback.palette , call = call )
124
126
125
127
position <- arg_match0(position , c(" left" , " right" , " top" , " bottom" ))
126
128
@@ -152,6 +154,7 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
152
154
153
155
aesthetics = aesthetics ,
154
156
palette = palette ,
157
+ fallback_palette = fallback.palette ,
155
158
156
159
range = ContinuousRange $ new(),
157
160
limits = limits ,
@@ -211,6 +214,7 @@ discrete_scale <- function(aesthetics, scale_name = deprecated(), palette, name
211
214
labels = waiver(), limits = NULL , expand = waiver(),
212
215
na.translate = TRUE , na.value = NA , drop = TRUE ,
213
216
guide = " legend" , position = " left" ,
217
+ fallback.palette = NULL ,
214
218
call = caller_call(),
215
219
super = ScaleDiscrete ) {
216
220
call <- call %|| % current_call()
@@ -221,6 +225,7 @@ discrete_scale <- function(aesthetics, scale_name = deprecated(), palette, name
221
225
aesthetics <- standardise_aes_names(aesthetics )
222
226
223
227
check_breaks_labels(breaks , labels , call = call )
228
+ check_fallback_palette(palette , fallback.palette , call = call )
224
229
225
230
# Convert formula input to function if appropriate
226
231
limits <- allow_lambda(limits )
@@ -251,6 +256,7 @@ discrete_scale <- function(aesthetics, scale_name = deprecated(), palette, name
251
256
252
257
aesthetics = aesthetics ,
253
258
palette = palette ,
259
+ fallback_palette = fallback.palette ,
254
260
255
261
range = DiscreteRange $ new(),
256
262
limits = limits ,
@@ -303,6 +309,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
303
309
right = TRUE , transform = " identity" ,
304
310
trans = deprecated(), show.limits = FALSE ,
305
311
guide = " bins" , position = " left" ,
312
+ fallback.palette = NULL ,
306
313
call = caller_call(),
307
314
super = ScaleBinned ) {
308
315
if (lifecycle :: is_present(scale_name )) {
@@ -318,6 +325,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
318
325
aesthetics <- standardise_aes_names(aesthetics )
319
326
320
327
check_breaks_labels(breaks , labels , call = call )
328
+ check_fallback_palette(palette , fallback.palette , call = call )
321
329
322
330
position <- arg_match0(position , c(" left" , " right" , " top" , " bottom" ))
323
331
@@ -346,6 +354,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
346
354
347
355
aesthetics = aesthetics ,
348
356
palette = palette ,
357
+ fallback_palette = fallback.palette ,
349
358
350
359
range = ContinuousRange $ new(),
351
360
limits = limits ,
@@ -1793,6 +1802,15 @@ check_continuous_limits <- function(limits, ...,
1793
1802
check_length(limits , 2L , arg = arg , call = call )
1794
1803
}
1795
1804
1805
+ check_fallback_palette <- function (pal , fallback , call = caller_env()) {
1806
+ if (! is.null(pal ) || is.function(fallback )) {
1807
+ return (invisible )
1808
+ }
1809
+ cli :: cli_abort(
1810
+ " When {.code palette = NULL}, the {.arg fallback.palette} must be defined."
1811
+ )
1812
+ }
1813
+
1796
1814
allow_lambda <- function (x ) {
1797
1815
# we check the 'call' class to prevent interpreting `bquote()` calls as a function
1798
1816
if (is_formula(x , lhs = FALSE ) && ! inherits(x , " call" )) as_function(x ) else x
0 commit comments