Skip to content

Commit a27af21

Browse files
authored
Fixes for revdep (#6717)
* fix typo * prevent partial matching of `label` parameter * fallbacks for fallbacks
1 parent eafcbb4 commit a27af21

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

R/layer.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ layer <- function(geom = NULL, stat = NULL,
167167
if (check.aes && length(extra_aes) > 0) {
168168
cli::cli_warn("Ignoring unknown aesthetics: {.field {extra_aes}}", call = call_env)
169169
}
170-
aes_params$label <- normalise_label(aes_params$label)
170+
aes_params[["label"]] <- normalise_label(aes_params[["label"]])
171171

172172
# adjust the legend draw key if requested
173173
geom <- set_draw_key(geom, key_glyph %||% params$key_glyph)
@@ -974,7 +974,7 @@ normalise_label <- function(label) {
974974
if (obj_is_list(label)) {
975975
# Ensure that each element in the list has length 1
976976
label[lengths(label) == 0] <- ""
977-
labels <- lapply(labels, `[`, 1)
977+
label <- lapply(label, `[`, 1)
978978
}
979979
if (is.expression(label)) {
980980
# Classed expressions, when converted to lists, retain their class.

R/scale-.R

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ continuous_scale <- function(aesthetics, scale_name = deprecated(), palette, nam
124124
aesthetics <- standardise_aes_names(aesthetics)
125125

126126
check_breaks_labels(breaks, labels, call = call)
127-
check_fallback_palette(palette, fallback.palette, call = call)
127+
fallback.palette <- validate_fallback_palette(
128+
palette, fallback.palette, aesthetics, discrete = FALSE,
129+
call = call
130+
)
128131

129132
position <- arg_match0(position, c("left", "right", "top", "bottom"))
130133

@@ -227,7 +230,10 @@ discrete_scale <- function(aesthetics, scale_name = deprecated(), palette, name
227230
aesthetics <- standardise_aes_names(aesthetics)
228231

229232
check_breaks_labels(breaks, labels, call = call)
230-
check_fallback_palette(palette, fallback.palette, call = call)
233+
fallback.palette <- validate_fallback_palette(
234+
palette, fallback.palette, aesthetics, discrete = TRUE,
235+
call = call
236+
)
231237

232238
# Convert formula input to function if appropriate
233239
limits <- allow_lambda(limits)
@@ -327,7 +333,10 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
327333
aesthetics <- standardise_aes_names(aesthetics)
328334

329335
check_breaks_labels(breaks, labels, call = call)
330-
check_fallback_palette(palette, fallback.palette, call = call)
336+
fallback.palette <- validate_fallback_palette(
337+
palette, fallback.palette, aesthetics, discrete = FALSE,
338+
call = call
339+
)
331340

332341
position <- arg_match0(position, c("left", "right", "top", "bottom"))
333342

@@ -1786,16 +1795,54 @@ check_continuous_limits <- function(limits, ...,
17861795
check_length(limits, 2L, arg = arg, call = call)
17871796
}
17881797

1789-
check_fallback_palette <- function(pal, fallback, call = caller_env()) {
1798+
allow_lambda <- function(x) {
1799+
# we check the 'call' class to prevent interpreting `bquote()` calls as a function
1800+
if (is_formula(x, lhs = FALSE) && !inherits(x, "call")) as_function(x) else x
1801+
}
1802+
1803+
validate_fallback_palette <- function(pal, fallback, aesthetic = "x",
1804+
discrete = FALSE, call = caller_env()) {
17901805
if (!is.null(pal) || is.function(fallback)) {
1791-
return(invisible())
1806+
return(pal %||% fallback)
1807+
}
1808+
aesthetic <- standardise_aes_names(aesthetic[1])
1809+
if (discrete) {
1810+
pal <- fallback_palette_discrete(aesthetic)
1811+
} else {
1812+
pal <- fallback_palette_continuous(aesthetic)
1813+
}
1814+
if (!is.null(pal)) {
1815+
return(pal)
17921816
}
17931817
cli::cli_abort(
17941818
"When {.code palette = NULL}, the {.arg fallback.palette} must be defined."
17951819
)
17961820
}
17971821

1798-
allow_lambda <- function(x) {
1799-
# we check the 'call' class to prevent interpreting `bquote()` calls as a function
1800-
if (is_formula(x, lhs = FALSE) && !inherits(x, "call")) as_function(x) else x
1822+
fallback_palette_discrete <- function(aesthetic) {
1823+
switch(
1824+
aesthetic,
1825+
colour = ,
1826+
fill = pal_hue(),
1827+
alpha = function(n) seq(0.1, 1, length.out = n),
1828+
linewidth = function(n) seq(2, 6, length.out = n),
1829+
linetype = pal_linetype(),
1830+
shape = pal_shape(),
1831+
size = function(n) sqrt(seq(4, 36, length.out = n)),
1832+
ggplot_global$theme_default[[paste0("palette.", aesthetic, ".discrete")]]
1833+
)
1834+
}
1835+
1836+
fallback_palette_continuous <- function(aesthetic) {
1837+
switch(
1838+
aesthetic,
1839+
colour = ,
1840+
fill = pal_seq_gradient("#132B43", "#56B1F7"),
1841+
alpha = pal_rescale(c(0.1, 1)),
1842+
linewidth = pal_rescale(c(1, 6)),
1843+
linetype = pal_binned(pal_linetype()),
1844+
shape = pal_binned(pal_shape()),
1845+
size = pal_area(),
1846+
ggplot_global$theme_default[[paste0("palette.", aes, ".continuous")]]
1847+
)
18011848
}

0 commit comments

Comments
 (0)