From 727bd71c26319c6c2dbf4321005bb3b8eaadcc79 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:11:15 +0100 Subject: [PATCH] Palette suffixes to prefixes (#398) --- NAMESPACE | 14 +++++++ NEWS.md | 2 + R/colour-manip.R | 8 ++-- R/colour-mapping.R | 8 ++-- R/documentation.R | 2 +- R/pal-area.R | 8 +++- R/pal-brewer.R | 16 ++++--- R/pal-dichromat.R | 14 ++++--- R/pal-gradient.R | 42 ++++++++++++------- R/pal-grey.R | 12 ++++-- R/pal-hue.R | 39 +++++++++-------- R/pal-identity.R | 7 +++- R/pal-linetype.R | 6 ++- R/pal-manual.R | 6 ++- R/pal-rescale.R | 6 ++- R/{pal-shape.R => pal-shape.r} | 6 ++- R/pal-viridis.R | 14 ++++--- R/scale-continuous.R | 8 ++-- R/scale-discrete.R | 2 +- README.Rmd | 4 +- README.md | 4 +- man/cscale.Rd | 8 ++-- man/dscale.Rd | 2 +- man/label_bytes.Rd | 4 ++ man/label_currency.Rd | 4 ++ man/label_date.Rd | 4 ++ man/label_number_si.Rd | 4 ++ man/label_ordinal.Rd | 4 ++ man/label_percent.Rd | 4 ++ man/{area_pal.Rd => pal_area.Rd} | 5 ++- man/{brewer_pal.Rd => pal_brewer.Rd} | 15 ++++--- man/{dichromat_pal.Rd => pal_dichromat.Rd} | 13 +++--- ...iv_gradient_pal.Rd => pal_div_gradient.Rd} | 18 +++++--- man/{gradient_n_pal.Rd => pal_gradient_n.Rd} | 5 ++- man/{grey_pal.Rd => pal_grey.Rd} | 11 +++-- man/{hue_pal.Rd => pal_hue.Rd} | 31 +++++++------- man/{identity_pal.Rd => pal_identity.Rd} | 5 ++- man/{linetype_pal.Rd => pal_linetype.Rd} | 5 ++- man/{manual_pal.Rd => pal_manual.Rd} | 5 ++- man/{rescale_pal.Rd => pal_rescale.Rd} | 5 ++- ...eq_gradient_pal.Rd => pal_seq_gradient.Rd} | 11 +++-- man/{shape_pal.Rd => pal_shape.Rd} | 5 ++- man/{viridis_pal.Rd => pal_viridis.Rd} | 13 +++--- man/show_col.Rd | 8 ++-- tests/testthat/test-pal-hue.R | 14 +++---- tests/testthat/test-pal-manual.R | 8 ++-- 46 files changed, 292 insertions(+), 147 deletions(-) rename R/{pal-shape.R => pal-shape.r} (85%) rename man/{area_pal.Rd => pal_area.Rd} (87%) rename man/{brewer_pal.Rd => pal_brewer.Rd} (74%) rename man/{dichromat_pal.Rd => pal_dichromat.Rd} (65%) rename man/{div_gradient_pal.Rd => pal_div_gradient.Rd} (64%) rename man/{gradient_n_pal.Rd => pal_gradient_n.Rd} (88%) rename man/{grey_pal.Rd => pal_grey.Rd} (67%) rename man/{hue_pal.Rd => pal_hue.Rd} (54%) rename man/{identity_pal.Rd => pal_identity.Rd} (81%) rename man/{linetype_pal.Rd => pal_linetype.Rd} (82%) rename man/{manual_pal.Rd => pal_manual.Rd} (83%) rename man/{rescale_pal.Rd => pal_rescale.Rd} (85%) rename man/{seq_gradient_pal.Rd => pal_seq_gradient.Rd} (69%) rename man/{shape_pal.Rd => pal_shape.Rd} (82%) rename man/{viridis_pal.Rd => pal_viridis.Rd} (79%) diff --git a/NAMESPACE b/NAMESPACE index 221150ac..ca790b6c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -137,6 +137,20 @@ export(ordinal_english) export(ordinal_format) export(ordinal_french) export(ordinal_spanish) +export(pal_area) +export(pal_brewer) +export(pal_dichromat) +export(pal_div_gradient) +export(pal_gradient_n) +export(pal_grey) +export(pal_hue) +export(pal_identity) +export(pal_linetype) +export(pal_manual) +export(pal_rescale) +export(pal_seq_gradient) +export(pal_shape) +export(pal_viridis) export(parse_format) export(percent) export(percent_format) diff --git a/NEWS.md b/NEWS.md index 83b6802d..e4203437 100644 --- a/NEWS.md +++ b/NEWS.md @@ -30,6 +30,8 @@ * Correct the domain calculation for `compose_trans()` (@mjskay, #408). * Transformation objects can optionally include the derivatives of the transform and the inverse transform (@mjskay, #322). +* Palette functions now have the `pal_`-prefix. The old `_pal`-suffixed versions + are kept for backward compatibility. # scales 1.2.1 diff --git a/R/colour-manip.R b/R/colour-manip.R index 3ea479e9..cb99c7cf 100644 --- a/R/colour-manip.R +++ b/R/colour-manip.R @@ -84,11 +84,11 @@ alpha <- function(colour, alpha = NA) { #' @importFrom graphics par plot rect text #' @keywords internal #' @examples -#' show_col(hue_pal()(9)) -#' show_col(hue_pal()(9), borders = NA) +#' show_col(pal_hue()(9)) +#' show_col(pal_hue()(9), borders = NA) #' -#' show_col(viridis_pal()(16)) -#' show_col(viridis_pal()(16), labels = FALSE) +#' show_col(pal_viridis()(16)) +#' show_col(pal_viridis()(16), labels = FALSE) show_col <- function(colours, labels = TRUE, borders = NULL, cex_label = 1, ncol = NULL) { n <- length(colours) diff --git a/R/colour-mapping.R b/R/colour-mapping.R index 76b82066..8ed05d0e 100644 --- a/R/colour-mapping.R +++ b/R/colour-mapping.R @@ -322,14 +322,14 @@ toPaletteFunc.character <- function(pal, alpha, nlevels) { if (length(pal) == 1 && pal %in% row.names(RColorBrewer::brewer.pal.info)) { paletteInfo <- RColorBrewer::brewer.pal.info[pal, ] if (!is.null(nlevels)) { - # brewer_pal will return NAs if you ask for more colors than the palette has - colors <- brewer_pal(palette = pal)(abs(nlevels)) + # pal_brewer will return NAs if you ask for more colors than the palette has + colors <- pal_brewer(palette = pal)(abs(nlevels)) colors <- colors[!is.na(colors)] } else { - colors <- brewer_pal(palette = pal)(RColorBrewer::brewer.pal.info[pal, "maxcolors"]) # Get all colors + colors <- pal_brewer(palette = pal)(RColorBrewer::brewer.pal.info[pal, "maxcolors"]) # Get all colors } } else if (length(pal) == 1 && pal %in% c("viridis", "magma", "inferno", "plasma")) { - colors <- viridis_pal(option = pal)(256) + colors <- pal_viridis(option = pal)(256) } else { colors <- pal } diff --git a/R/documentation.R b/R/documentation.R index 6b8fcc68..594c942f 100644 --- a/R/documentation.R +++ b/R/documentation.R @@ -9,4 +9,4 @@ seealso <- function(pattern) { seealso_trans <- function() seealso("_trans$") -seealso_pal <- function() seealso("_pal$") +seealso_pal <- function() seealso("^pal_") diff --git a/R/pal-area.R b/R/pal-area.R index 7ce1d40d..ecc87365 100644 --- a/R/pal-area.R +++ b/R/pal-area.R @@ -3,14 +3,18 @@ #' @param range Numeric vector of length two, giving range of possible sizes. #' Should be greater than 0. #' @export -area_pal <- function(range = c(1, 6)) { +pal_area <- function(range = c(1, 6)) { force(range) function(x) rescale(sqrt(x), range, c(0, 1)) } +#' @export +#' @rdname pal_area +area_pal <- pal_area + #' @param max A number representing the maximum size. #' @export -#' @rdname area_pal +#' @rdname pal_area abs_area <- function(max) { force(max) function(x) rescale(sqrt(abs(x)), c(0, max), c(0, 1)) diff --git a/R/pal-brewer.R b/R/pal-brewer.R index 72c5b358..597eee74 100644 --- a/R/pal-brewer.R +++ b/R/pal-brewer.R @@ -10,14 +10,14 @@ #' @references #' @export #' @examples -#' show_col(brewer_pal()(10)) -#' show_col(brewer_pal("div")(5)) -#' show_col(brewer_pal(palette = "Greens")(5)) +#' show_col(pal_brewer()(10)) +#' show_col(pal_brewer("div")(5)) +#' show_col(pal_brewer(palette = "Greens")(5)) #' #' # Can use with gradient_n to create a continuous gradient -#' cols <- brewer_pal("div")(5) -#' show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30))) -brewer_pal <- function(type = "seq", palette = 1, direction = 1) { +#' cols <- pal_brewer("div")(5) +#' show_col(pal_gradient_n(cols)(seq(0, 1, length.out = 30))) +pal_brewer <- function(type = "seq", palette = 1, direction = 1) { pal <- pal_name(palette, type) force(direction) function(n) { @@ -42,6 +42,10 @@ brewer_pal <- function(type = "seq", palette = 1, direction = 1) { } } +#' @export +#' @rdname pal_brewer +brewer_pal <- pal_brewer + pal_name <- function(palette, type) { if (is.character(palette)) { if (!palette %in% unlist(brewer)) { diff --git a/R/pal-dichromat.R b/R/pal-dichromat.R index 65ebe98b..fcf5b8fa 100644 --- a/R/pal-dichromat.R +++ b/R/pal-dichromat.R @@ -5,14 +5,14 @@ #' @export #' @examples #' if (requireNamespace("dichromat", quietly = TRUE)) { -#' show_col(dichromat_pal("BluetoOrange.10")(10)) -#' show_col(dichromat_pal("BluetoOrange.10")(5)) +#' show_col(pal_dichromat("BluetoOrange.10")(10)) +#' show_col(pal_dichromat("BluetoOrange.10")(5)) #' #' # Can use with gradient_n to create a continous gradient -#' cols <- dichromat_pal("DarkRedtoBlue.12")(12) -#' show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30))) +#' cols <- pal_dichromat("DarkRedtoBlue.12")(12) +#' show_col(pal_gradient_n(cols)(seq(0, 1, length.out = 30))) #' } -dichromat_pal <- function(name) { +pal_dichromat <- function(name) { check_installed("dichromat") if (!any(name == names(dichromat::colorschemes))) { @@ -23,6 +23,10 @@ dichromat_pal <- function(name) { function(n) pal[seq_len(n)] } +#' @export +#' @rdname pal_dichromat +dichromat_pal <- pal_dichromat + dichromat_schemes <- function() { if (requireNamespace("dichromat", quietly = TRUE)) { diff --git a/R/pal-gradient.R b/R/pal-gradient.R index aff3ce1a..ae4e23d5 100644 --- a/R/pal-gradient.R +++ b/R/pal-gradient.R @@ -9,9 +9,9 @@ #' other values are deprecated. #' @export -gradient_n_pal <- function(colours, values = NULL, space = "Lab") { +pal_gradient_n <- function(colours, values = NULL, space = "Lab") { if (!identical(space, "Lab")) { - lifecycle::deprecate_warn("0.3.0", "gradient_n_pal(space = 'only supports be \"Lab\"')") + lifecycle::deprecate_warn("0.3.0", "pal_gradient_n(space = 'only supports be \"Lab\"')") } ramp <- colour_ramp(colours) force(values) @@ -31,41 +31,53 @@ gradient_n_pal <- function(colours, values = NULL, space = "Lab") { } } +#' @export +#' @rdname pal_gradient_n +gradient_n_pal <- pal_gradient_n + #' Diverging colour gradient (continuous). #' #' @param low colour for low end of gradient. #' @param mid colour for mid point #' @param high colour for high end of gradient. -#' @inheritParams gradient_n_pal +#' @inheritParams pal_gradient_n #' @export #' @examples #' x <- seq(-1, 1, length.out = 100) #' r <- sqrt(outer(x^2, x^2, "+")) -#' image(r, col = div_gradient_pal()(seq(0, 1, length.out = 12))) -#' image(r, col = div_gradient_pal()(seq(0, 1, length.out = 30))) -#' image(r, col = div_gradient_pal()(seq(0, 1, length.out = 100))) +#' image(r, col = pal_div_gradient()(seq(0, 1, length.out = 12))) +#' image(r, col = pal_div_gradient()(seq(0, 1, length.out = 30))) +#' image(r, col = pal_div_gradient()(seq(0, 1, length.out = 100))) #' #' library(munsell) -#' pal <- div_gradient_pal(low = mnsl(complement("10R 4/6"), fix = TRUE)) +#' pal <- pal_div_gradient(low = mnsl(complement("10R 4/6"), fix = TRUE)) #' image(r, col = pal(seq(0, 1, length.out = 100))) #' @importFrom munsell mnsl -div_gradient_pal <- function(low = mnsl("10B 4/6"), mid = mnsl("N 8/0"), high = mnsl("10R 4/6"), space = "Lab") { - gradient_n_pal(c(low, mid, high), space = space) +pal_div_gradient <- function(low = mnsl("10B 4/6"), mid = mnsl("N 8/0"), high = mnsl("10R 4/6"), space = "Lab") { + pal_gradient_n(c(low, mid, high), space = space) } +#' @export +#' @rdname pal_div_gradient +div_gradient_pal <- pal_div_gradient + #' Sequential colour gradient palette (continuous) #' #' @param low colour for low end of gradient. #' @param high colour for high end of gradient. -#' @inheritParams gradient_n_pal +#' @inheritParams pal_gradient_n #' @export #' @examples #' x <- seq(0, 1, length.out = 25) -#' show_col(seq_gradient_pal()(x)) -#' show_col(seq_gradient_pal("white", "black")(x)) +#' show_col(pal_seq_gradient()(x)) +#' show_col(pal_seq_gradient("white", "black")(x)) #' #' library(munsell) -#' show_col(seq_gradient_pal("white", mnsl("10R 4/6"))(x)) -seq_gradient_pal <- function(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab") { - gradient_n_pal(c(low, high), space = space) +#' show_col(pal_seq_gradient("white", mnsl("10R 4/6"))(x)) +pal_seq_gradient <- function(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab") { + pal_gradient_n(c(low, high), space = space) } + +#' @export +#' @rdname pal_seq_gradient +seq_gradient_pal <- pal_seq_gradient diff --git a/R/pal-grey.R b/R/pal-grey.R index 7125b575..fa0b558c 100644 --- a/R/pal-grey.R +++ b/R/pal-grey.R @@ -2,12 +2,16 @@ #' #' @param start grey value at low end of palette #' @param end grey value at high end of palette -#' @seealso [seq_gradient_pal()] for continuous version +#' @seealso [pal_seq_gradient()] for continuous version #' @export #' @examples -#' show_col(grey_pal()(25)) -#' show_col(grey_pal(0, 1)(25)) -grey_pal <- function(start = 0.2, end = 0.8) { +#' show_col(pal_grey()(25)) +#' show_col(pal_grey(0, 1)(25)) +pal_grey <- function(start = 0.2, end = 0.8) { force_all(start, end) function(n) grDevices::grey.colors(n, start = start, end = end) } + +#' @export +#' @rdname pal_grey +grey_pal <- pal_grey diff --git a/R/pal-hue.R b/R/pal-hue.R index 5dcdb5aa..2826a424 100644 --- a/R/pal-hue.R +++ b/R/pal-hue.R @@ -9,25 +9,25 @@ #' 1 = clockwise, -1 = counter-clockwise #' @export #' @examples -#' show_col(hue_pal()(4)) -#' show_col(hue_pal()(9)) -#' show_col(hue_pal(l = 90)(9)) -#' show_col(hue_pal(l = 30)(9)) +#' show_col(pal_hue()(4)) +#' show_col(pal_hue()(9)) +#' show_col(pal_hue(l = 90)(9)) +#' show_col(pal_hue(l = 30)(9)) #' -#' show_col(hue_pal()(9)) -#' show_col(hue_pal(direction = -1)(9)) -#' show_col(hue_pal(h.start = 30)(9)) -#' show_col(hue_pal(h.start = 90)(9)) +#' show_col(pal_hue()(9)) +#' show_col(pal_hue(direction = -1)(9)) +#' show_col(pal_hue(h.start = 30)(9)) +#' show_col(pal_hue(h.start = 90)(9)) #' -#' show_col(hue_pal()(9)) -#' show_col(hue_pal(h = c(0, 90))(9)) -#' show_col(hue_pal(h = c(90, 180))(9)) -#' show_col(hue_pal(h = c(180, 270))(9)) -#' show_col(hue_pal(h = c(270, 360))(9)) -hue_pal <- function(h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1) { - if (length(h) != 2) cli::cli_abort("{.arg h} must have length 2") - if (length(l) != 1) cli::cli_abort("{.arg l} must have length 1") - if (length(c) != 1) cli::cli_abort("{.arg c} must have length 1") +#' show_col(pal_hue()(9)) +#' show_col(pal_hue(h = c(0, 90))(9)) +#' show_col(pal_hue(h = c(90, 180))(9)) +#' show_col(pal_hue(h = c(180, 270))(9)) +#' show_col(pal_hue(h = c(270, 360))(9)) +pal_hue <- function(h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1) { + if (length(h) != 2) cli::cli_abort("{.arg h} must have length 2.") + if (length(l) != 1) cli::cli_abort("{.arg l} must have length 1.") + if (length(c) != 1) cli::cli_abort("{.arg c} must have length 1.") force_all(h, c, l, h.start, direction) function(n) { if (n == 0) { @@ -52,3 +52,8 @@ hue_pal <- function(h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction } } } + +#' @export +#' @rdname pal_hue +hue_pal <- pal_hue + diff --git a/R/pal-identity.R b/R/pal-identity.R index a68a0565..fef79227 100644 --- a/R/pal-identity.R +++ b/R/pal-identity.R @@ -3,6 +3,11 @@ #' Leaves values unchanged - useful when the data is already scaled. #' #' @export -identity_pal <- function() { +pal_identity <- function() { function(x) x } + + +#' @export +#' @rdname pal_identity +identity_pal <- pal_identity diff --git a/R/pal-linetype.R b/R/pal-linetype.R index c03728df..8dbb0d23 100644 --- a/R/pal-linetype.R +++ b/R/pal-linetype.R @@ -3,7 +3,7 @@ #' Based on a set supplied by Richard Pearson, University of Manchester #' #' @export -linetype_pal <- function() { +pal_linetype <- function() { types <- c( "solid", "22", "42", "44", "13", "1343", "73", "2262", "12223242", "F282", "F4448444", "224282F2", "F1" @@ -13,3 +13,7 @@ linetype_pal <- function() { types[seq_len(n)] } } + +#' @export +#' @rdname pal_linetype +linetype_pal <- pal_linetype diff --git a/R/pal-manual.R b/R/pal-manual.R index 8a4bef85..923a4f9b 100644 --- a/R/pal-manual.R +++ b/R/pal-manual.R @@ -2,7 +2,7 @@ #' #' @param values vector of values to be used as a palette. #' @export -manual_pal <- function(values) { +pal_manual <- function(values) { force(values) function(n) { n_values <- length(values) @@ -12,3 +12,7 @@ manual_pal <- function(values) { unname(values[seq_len(n)]) } } + +#' @export +#' @rdname pal_manual +manual_pal <- pal_manual diff --git a/R/pal-rescale.R b/R/pal-rescale.R index 8c32ab6b..bbff22fa 100644 --- a/R/pal-rescale.R +++ b/R/pal-rescale.R @@ -6,9 +6,13 @@ #' @param range Numeric vector of length two, giving range of possible #' values. Should be between 0 and 1. #' @export -rescale_pal <- function(range = c(0.1, 1)) { +pal_rescale <- function(range = c(0.1, 1)) { force(range) function(x) { rescale(x, range, c(0, 1)) } } + +#' @export +#' @rdname pal_rescale +rescale_pal <- pal_rescale diff --git a/R/pal-shape.R b/R/pal-shape.r similarity index 85% rename from R/pal-shape.R rename to R/pal-shape.r index b0d9d76f..7c93ed3e 100644 --- a/R/pal-shape.R +++ b/R/pal-shape.r @@ -2,7 +2,7 @@ #' #' @param solid should shapes be solid or not? #' @export -shape_pal <- function(solid = TRUE) { +pal_shape <- function(solid = TRUE) { force(solid) function(n) { if (n > 6) { @@ -19,3 +19,7 @@ shape_pal <- function(solid = TRUE) { } } } + +#' @export +#' @rdname pal_shape +shape_pal <- pal_shape diff --git a/R/pal-viridis.R b/R/pal-viridis.R index 94e12656..04d02d55 100644 --- a/R/pal-viridis.R +++ b/R/pal-viridis.R @@ -6,13 +6,17 @@ #' @references #' @export #' @examples -#' show_col(viridis_pal()(10)) -#' show_col(viridis_pal(direction = -1)(6)) -#' show_col(viridis_pal(begin = 0.2, end = 0.8)(4)) -#' show_col(viridis_pal(option = "plasma")(6)) -viridis_pal <- function(alpha = 1, begin = 0, end = 1, direction = 1, option = "D") { +#' show_col(pal_viridis()(10)) +#' show_col(pal_viridis(direction = -1)(6)) +#' show_col(pal_viridis(begin = 0.2, end = 0.8)(4)) +#' show_col(pal_viridis(option = "plasma")(6)) +pal_viridis <- function(alpha = 1, begin = 0, end = 1, direction = 1, option = "D") { force_all(alpha, begin, end, direction, option) function(n) { viridisLite::viridis(n, alpha, begin, end, direction, option) } } + +#' @export +#' @rdname pal_viridis +viridis_pal <- pal_viridis diff --git a/R/scale-continuous.R b/R/scale-continuous.R index a26334ae..f49c3f68 100644 --- a/R/scale-continuous.R +++ b/R/scale-continuous.R @@ -14,14 +14,14 @@ #' \Sexpr[results=rd,stage=build]{scales:::seealso_trans()}. #' @export #' @examples -#' with(mtcars, plot(disp, mpg, cex = cscale(hp, rescale_pal()))) -#' with(mtcars, plot(disp, mpg, cex = cscale(hp, rescale_pal(), +#' with(mtcars, plot(disp, mpg, cex = cscale(hp, pal_rescale()))) +#' with(mtcars, plot(disp, mpg, cex = cscale(hp, pal_rescale(), #' trans = sqrt_trans() #' ))) -#' with(mtcars, plot(disp, mpg, cex = cscale(hp, area_pal()))) +#' with(mtcars, plot(disp, mpg, cex = cscale(hp, pal_area()))) #' with(mtcars, plot(disp, mpg, #' pch = 20, cex = 5, -#' col = cscale(hp, seq_gradient_pal("grey80", "black")) +#' col = cscale(hp, pal_seq_gradient("grey80", "black")) #' )) cscale <- function(x, palette, na.value = NA_real_, trans = identity_trans()) { if (!is.trans(trans)) cli::cli_abort("{.arg trans} must be a {.cls trans} object") diff --git a/R/scale-discrete.R b/R/scale-discrete.R index 38ec0c36..1766495d 100644 --- a/R/scale-discrete.R +++ b/R/scale-discrete.R @@ -7,7 +7,7 @@ #' @examples #' with(mtcars, plot(disp, mpg, #' pch = 20, cex = 3, -#' col = dscale(factor(cyl), brewer_pal()) +#' col = dscale(factor(cyl), pal_brewer()) #' )) dscale <- function(x, palette, na.value = NA) { limits <- train_discrete(x) diff --git a/README.Rmd b/README.Rmd index 86845388..cdf373f5 100644 --- a/README.Rmd +++ b/README.Rmd @@ -86,10 +86,10 @@ Scales colour palettes are used to power the scales in ggplot2, but you can use ```{r, palettes} library(scales) # pull a list of colours from any palette -viridis_pal()(4) +pal_viridis()(4) # use in combination with baseR `palette()` to set new defaults -palette(brewer_pal(palette = "Set2")(4)) +palette(pal_brewer(palette = "Set2")(4)) par(mar = c(5, 5, 1, 1)) plot(Sepal.Length ~ Sepal.Width, data = iris, col = Species, pch = 20) ``` diff --git a/README.md b/README.md index 5a2d861c..4343bb55 100644 --- a/README.md +++ b/README.md @@ -96,11 +96,11 @@ might apply them to a base plot. ``` r library(scales) # pull a list of colours from any palette -viridis_pal()(4) +pal_viridis()(4) #> [1] "#440154FF" "#31688EFF" "#35B779FF" "#FDE725FF" # use in combination with baseR `palette()` to set new defaults -palette(brewer_pal(palette = "Set2")(4)) +palette(pal_brewer(palette = "Set2")(4)) par(mar = c(5, 5, 1, 1)) plot(Sepal.Length ~ Sepal.Width, data = iris, col = Species, pch = 20) ``` diff --git a/man/cscale.Rd b/man/cscale.Rd index 1c65f54d..8783e2c0 100644 --- a/man/cscale.Rd +++ b/man/cscale.Rd @@ -27,13 +27,13 @@ Built in transformations: Continuous scale } \examples{ -with(mtcars, plot(disp, mpg, cex = cscale(hp, rescale_pal()))) -with(mtcars, plot(disp, mpg, cex = cscale(hp, rescale_pal(), +with(mtcars, plot(disp, mpg, cex = cscale(hp, pal_rescale()))) +with(mtcars, plot(disp, mpg, cex = cscale(hp, pal_rescale(), trans = sqrt_trans() ))) -with(mtcars, plot(disp, mpg, cex = cscale(hp, area_pal()))) +with(mtcars, plot(disp, mpg, cex = cscale(hp, pal_area()))) with(mtcars, plot(disp, mpg, pch = 20, cex = 5, - col = cscale(hp, seq_gradient_pal("grey80", "black")) + col = cscale(hp, pal_seq_gradient("grey80", "black")) )) } diff --git a/man/dscale.Rd b/man/dscale.Rd index 212253eb..87972ba8 100644 --- a/man/dscale.Rd +++ b/man/dscale.Rd @@ -19,6 +19,6 @@ Discrete scale \examples{ with(mtcars, plot(disp, mpg, pch = 20, cex = 3, - col = dscale(factor(cyl), brewer_pal()) + col = dscale(factor(cyl), pal_brewer()) )) } diff --git a/man/label_bytes.Rd b/man/label_bytes.Rd index d25cae27..fd842fdd 100644 --- a/man/label_bytes.Rd +++ b/man/label_bytes.Rd @@ -42,6 +42,10 @@ decimal point.} \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. \item \code{"plus"}: preceded by \code{+}, e.g. \code{+1}. +\item \code{"space"}: preceded by a Unicode "figure space", i.e., a space equally +as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space +can ensure numbers remain properly aligned when they are left- or +right-justified. }} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ diff --git a/man/label_currency.Rd b/man/label_currency.Rd index 40bead59..0c9f5c2d 100644 --- a/man/label_currency.Rd +++ b/man/label_currency.Rd @@ -44,6 +44,10 @@ width (see \code{\link[base:format]{base::format()}}).} \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. \item \code{"plus"}: preceded by \code{+}, e.g. \code{+1}. +\item \code{"space"}: preceded by a Unicode "figure space", i.e., a space equally +as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space +can ensure numbers remain properly aligned when they are left- or +right-justified. }} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ diff --git a/man/label_date.Rd b/man/label_date.Rd index 9c510d4a..df3cebda 100644 --- a/man/label_date.Rd +++ b/man/label_date.Rd @@ -57,6 +57,10 @@ decimal point.} \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. \item \code{"plus"}: preceded by \code{+}, e.g. \code{+1}. +\item \code{"space"}: preceded by a Unicode "figure space", i.e., a space equally +as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space +can ensure numbers remain properly aligned when they are left- or +right-justified. }} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ diff --git a/man/label_number_si.Rd b/man/label_number_si.Rd index 85019af4..fa6a7adb 100644 --- a/man/label_number_si.Rd +++ b/man/label_number_si.Rd @@ -35,6 +35,10 @@ decimal point.} \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. \item \code{"plus"}: preceded by \code{+}, e.g. \code{+1}. +\item \code{"space"}: preceded by a Unicode "figure space", i.e., a space equally +as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space +can ensure numbers remain properly aligned when they are left- or +right-justified. }} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ diff --git a/man/label_ordinal.Rd b/man/label_ordinal.Rd index 62945380..e6de359c 100644 --- a/man/label_ordinal.Rd +++ b/man/label_ordinal.Rd @@ -47,6 +47,10 @@ decimal point.} \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. \item \code{"plus"}: preceded by \code{+}, e.g. \code{+1}. +\item \code{"space"}: preceded by a Unicode "figure space", i.e., a space equally +as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space +can ensure numbers remain properly aligned when they are left- or +right-justified. }} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ diff --git a/man/label_percent.Rd b/man/label_percent.Rd index ffef1e54..993e121d 100644 --- a/man/label_percent.Rd +++ b/man/label_percent.Rd @@ -48,6 +48,10 @@ width (see \code{\link[base:format]{base::format()}}).} \itemize{ \item \code{"none"} (the default): no change, e.g. \code{1}. \item \code{"plus"}: preceded by \code{+}, e.g. \code{+1}. +\item \code{"space"}: preceded by a Unicode "figure space", i.e., a space equally +as wide as a number or \code{+}. Compared to \code{"none"}, adding a figure space +can ensure numbers remain properly aligned when they are left- or +right-justified. }} \item{\code{style_negative}}{A string that determines the style of negative numbers: \itemize{ diff --git a/man/area_pal.Rd b/man/pal_area.Rd similarity index 87% rename from man/area_pal.Rd rename to man/pal_area.Rd index 2dc3184c..b388b53a 100644 --- a/man/area_pal.Rd +++ b/man/pal_area.Rd @@ -1,10 +1,13 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-area.R -\name{area_pal} +\name{pal_area} +\alias{pal_area} \alias{area_pal} \alias{abs_area} \title{Area palettes (continuous)} \usage{ +pal_area(range = c(1, 6)) + area_pal(range = c(1, 6)) abs_area(max) diff --git a/man/brewer_pal.Rd b/man/pal_brewer.Rd similarity index 74% rename from man/brewer_pal.Rd rename to man/pal_brewer.Rd index dd7e72be..c129cfc8 100644 --- a/man/brewer_pal.Rd +++ b/man/pal_brewer.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-brewer.R -\name{brewer_pal} +\name{pal_brewer} +\alias{pal_brewer} \alias{brewer_pal} \title{Colour Brewer palette (discrete)} \usage{ +pal_brewer(type = "seq", palette = 1, direction = 1) + brewer_pal(type = "seq", palette = 1, direction = 1) } \arguments{ @@ -21,13 +24,13 @@ order of colours is reversed.} Colour Brewer palette (discrete) } \examples{ -show_col(brewer_pal()(10)) -show_col(brewer_pal("div")(5)) -show_col(brewer_pal(palette = "Greens")(5)) +show_col(pal_brewer()(10)) +show_col(pal_brewer("div")(5)) +show_col(pal_brewer(palette = "Greens")(5)) # Can use with gradient_n to create a continuous gradient -cols <- brewer_pal("div")(5) -show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30))) +cols <- pal_brewer("div")(5) +show_col(pal_gradient_n(cols)(seq(0, 1, length.out = 30))) } \references{ \url{https://colorbrewer2.org} diff --git a/man/dichromat_pal.Rd b/man/pal_dichromat.Rd similarity index 65% rename from man/dichromat_pal.Rd rename to man/pal_dichromat.Rd index e79862e7..a0ba08ca 100644 --- a/man/dichromat_pal.Rd +++ b/man/pal_dichromat.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-dichromat.R -\name{dichromat_pal} +\name{pal_dichromat} +\alias{pal_dichromat} \alias{dichromat_pal} \title{Dichromat (colour-blind) palette (discrete)} \usage{ +pal_dichromat(name) + dichromat_pal(name) } \arguments{ @@ -15,11 +18,11 @@ Dichromat (colour-blind) palette (discrete) } \examples{ if (requireNamespace("dichromat", quietly = TRUE)) { - show_col(dichromat_pal("BluetoOrange.10")(10)) - show_col(dichromat_pal("BluetoOrange.10")(5)) + show_col(pal_dichromat("BluetoOrange.10")(10)) + show_col(pal_dichromat("BluetoOrange.10")(5)) # Can use with gradient_n to create a continous gradient - cols <- dichromat_pal("DarkRedtoBlue.12")(12) - show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30))) + cols <- pal_dichromat("DarkRedtoBlue.12")(12) + show_col(pal_gradient_n(cols)(seq(0, 1, length.out = 30))) } } diff --git a/man/div_gradient_pal.Rd b/man/pal_div_gradient.Rd similarity index 64% rename from man/div_gradient_pal.Rd rename to man/pal_div_gradient.Rd index 33aaa41d..c633eef9 100644 --- a/man/div_gradient_pal.Rd +++ b/man/pal_div_gradient.Rd @@ -1,9 +1,17 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-gradient.R -\name{div_gradient_pal} +\name{pal_div_gradient} +\alias{pal_div_gradient} \alias{div_gradient_pal} \title{Diverging colour gradient (continuous).} \usage{ +pal_div_gradient( + low = mnsl("10B 4/6"), + mid = mnsl("N 8/0"), + high = mnsl("10R 4/6"), + space = "Lab" +) + div_gradient_pal( low = mnsl("10B 4/6"), mid = mnsl("N 8/0"), @@ -27,11 +35,11 @@ Diverging colour gradient (continuous). \examples{ x <- seq(-1, 1, length.out = 100) r <- sqrt(outer(x^2, x^2, "+")) -image(r, col = div_gradient_pal()(seq(0, 1, length.out = 12))) -image(r, col = div_gradient_pal()(seq(0, 1, length.out = 30))) -image(r, col = div_gradient_pal()(seq(0, 1, length.out = 100))) +image(r, col = pal_div_gradient()(seq(0, 1, length.out = 12))) +image(r, col = pal_div_gradient()(seq(0, 1, length.out = 30))) +image(r, col = pal_div_gradient()(seq(0, 1, length.out = 100))) library(munsell) -pal <- div_gradient_pal(low = mnsl(complement("10R 4/6"), fix = TRUE)) +pal <- pal_div_gradient(low = mnsl(complement("10R 4/6"), fix = TRUE)) image(r, col = pal(seq(0, 1, length.out = 100))) } diff --git a/man/gradient_n_pal.Rd b/man/pal_gradient_n.Rd similarity index 88% rename from man/gradient_n_pal.Rd rename to man/pal_gradient_n.Rd index 7cbbefeb..239dcc22 100644 --- a/man/gradient_n_pal.Rd +++ b/man/pal_gradient_n.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-gradient.R -\name{gradient_n_pal} +\name{pal_gradient_n} +\alias{pal_gradient_n} \alias{gradient_n_pal} \title{Arbitrary colour gradient palette (continuous)} \usage{ +pal_gradient_n(colours, values = NULL, space = "Lab") + gradient_n_pal(colours, values = NULL, space = "Lab") } \arguments{ diff --git a/man/grey_pal.Rd b/man/pal_grey.Rd similarity index 67% rename from man/grey_pal.Rd rename to man/pal_grey.Rd index 7bd01256..08fab5f3 100644 --- a/man/grey_pal.Rd +++ b/man/pal_grey.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-grey.R -\name{grey_pal} +\name{pal_grey} +\alias{pal_grey} \alias{grey_pal} \title{Grey scale palette (discrete)} \usage{ +pal_grey(start = 0.2, end = 0.8) + grey_pal(start = 0.2, end = 0.8) } \arguments{ @@ -15,9 +18,9 @@ grey_pal(start = 0.2, end = 0.8) Grey scale palette (discrete) } \examples{ -show_col(grey_pal()(25)) -show_col(grey_pal(0, 1)(25)) +show_col(pal_grey()(25)) +show_col(pal_grey(0, 1)(25)) } \seealso{ -\code{\link[=seq_gradient_pal]{seq_gradient_pal()}} for continuous version +\code{\link[=pal_seq_gradient]{pal_seq_gradient()}} for continuous version } diff --git a/man/hue_pal.Rd b/man/pal_hue.Rd similarity index 54% rename from man/hue_pal.Rd rename to man/pal_hue.Rd index 3abcd8bd..d105de05 100644 --- a/man/hue_pal.Rd +++ b/man/pal_hue.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-hue.R -\name{hue_pal} +\name{pal_hue} +\alias{pal_hue} \alias{hue_pal} \title{Hue palette (discrete)} \usage{ +pal_hue(h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1) + hue_pal(h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1) } \arguments{ @@ -23,19 +26,19 @@ combination of hue and luminance.} Hue palette (discrete) } \examples{ -show_col(hue_pal()(4)) -show_col(hue_pal()(9)) -show_col(hue_pal(l = 90)(9)) -show_col(hue_pal(l = 30)(9)) +show_col(pal_hue()(4)) +show_col(pal_hue()(9)) +show_col(pal_hue(l = 90)(9)) +show_col(pal_hue(l = 30)(9)) -show_col(hue_pal()(9)) -show_col(hue_pal(direction = -1)(9)) -show_col(hue_pal(h.start = 30)(9)) -show_col(hue_pal(h.start = 90)(9)) +show_col(pal_hue()(9)) +show_col(pal_hue(direction = -1)(9)) +show_col(pal_hue(h.start = 30)(9)) +show_col(pal_hue(h.start = 90)(9)) -show_col(hue_pal()(9)) -show_col(hue_pal(h = c(0, 90))(9)) -show_col(hue_pal(h = c(90, 180))(9)) -show_col(hue_pal(h = c(180, 270))(9)) -show_col(hue_pal(h = c(270, 360))(9)) +show_col(pal_hue()(9)) +show_col(pal_hue(h = c(0, 90))(9)) +show_col(pal_hue(h = c(90, 180))(9)) +show_col(pal_hue(h = c(180, 270))(9)) +show_col(pal_hue(h = c(270, 360))(9)) } diff --git a/man/identity_pal.Rd b/man/pal_identity.Rd similarity index 81% rename from man/identity_pal.Rd rename to man/pal_identity.Rd index 028a6246..a4d2c243 100644 --- a/man/identity_pal.Rd +++ b/man/pal_identity.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-identity.R -\name{identity_pal} +\name{pal_identity} +\alias{pal_identity} \alias{identity_pal} \title{Identity palette} \usage{ +pal_identity() + identity_pal() } \description{ diff --git a/man/linetype_pal.Rd b/man/pal_linetype.Rd similarity index 82% rename from man/linetype_pal.Rd rename to man/pal_linetype.Rd index d4404b8f..7c79c0d6 100644 --- a/man/linetype_pal.Rd +++ b/man/pal_linetype.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-linetype.R -\name{linetype_pal} +\name{pal_linetype} +\alias{pal_linetype} \alias{linetype_pal} \title{Line type palette (discrete)} \usage{ +pal_linetype() + linetype_pal() } \description{ diff --git a/man/manual_pal.Rd b/man/pal_manual.Rd similarity index 83% rename from man/manual_pal.Rd rename to man/pal_manual.Rd index b7ff407d..394abff2 100644 --- a/man/manual_pal.Rd +++ b/man/pal_manual.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-manual.R -\name{manual_pal} +\name{pal_manual} +\alias{pal_manual} \alias{manual_pal} \title{Manual palette (discrete)} \usage{ +pal_manual(values) + manual_pal(values) } \arguments{ diff --git a/man/rescale_pal.Rd b/man/pal_rescale.Rd similarity index 85% rename from man/rescale_pal.Rd rename to man/pal_rescale.Rd index 7fa3a584..74104b83 100644 --- a/man/rescale_pal.Rd +++ b/man/pal_rescale.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-rescale.R -\name{rescale_pal} +\name{pal_rescale} +\alias{pal_rescale} \alias{rescale_pal} \title{Rescale palette (continuous)} \usage{ +pal_rescale(range = c(0.1, 1)) + rescale_pal(range = c(0.1, 1)) } \arguments{ diff --git a/man/seq_gradient_pal.Rd b/man/pal_seq_gradient.Rd similarity index 69% rename from man/seq_gradient_pal.Rd rename to man/pal_seq_gradient.Rd index 32973b3f..253e133e 100644 --- a/man/seq_gradient_pal.Rd +++ b/man/pal_seq_gradient.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-gradient.R -\name{seq_gradient_pal} +\name{pal_seq_gradient} +\alias{pal_seq_gradient} \alias{seq_gradient_pal} \title{Sequential colour gradient palette (continuous)} \usage{ +pal_seq_gradient(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab") + seq_gradient_pal(low = mnsl("10B 4/6"), high = mnsl("10R 4/6"), space = "Lab") } \arguments{ @@ -19,9 +22,9 @@ Sequential colour gradient palette (continuous) } \examples{ x <- seq(0, 1, length.out = 25) -show_col(seq_gradient_pal()(x)) -show_col(seq_gradient_pal("white", "black")(x)) +show_col(pal_seq_gradient()(x)) +show_col(pal_seq_gradient("white", "black")(x)) library(munsell) -show_col(seq_gradient_pal("white", mnsl("10R 4/6"))(x)) +show_col(pal_seq_gradient("white", mnsl("10R 4/6"))(x)) } diff --git a/man/shape_pal.Rd b/man/pal_shape.Rd similarity index 82% rename from man/shape_pal.Rd rename to man/pal_shape.Rd index a3c69ccc..367e576e 100644 --- a/man/shape_pal.Rd +++ b/man/pal_shape.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-shape.R -\name{shape_pal} +\name{pal_shape} +\alias{pal_shape} \alias{shape_pal} \title{Shape palette (discrete)} \usage{ +pal_shape(solid = TRUE) + shape_pal(solid = TRUE) } \arguments{ diff --git a/man/viridis_pal.Rd b/man/pal_viridis.Rd similarity index 79% rename from man/viridis_pal.Rd rename to man/pal_viridis.Rd index 0fa20328..d4b989c2 100644 --- a/man/viridis_pal.Rd +++ b/man/pal_viridis.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/pal-viridis.R -\name{viridis_pal} +\name{pal_viridis} +\alias{pal_viridis} \alias{viridis_pal} \title{Viridis palette} \usage{ +pal_viridis(alpha = 1, begin = 0, end = 1, direction = 1, option = "D") + viridis_pal(alpha = 1, begin = 0, end = 1, direction = 1, option = "D") } \arguments{ @@ -34,10 +37,10 @@ Eight options are available: Viridis palette } \examples{ -show_col(viridis_pal()(10)) -show_col(viridis_pal(direction = -1)(6)) -show_col(viridis_pal(begin = 0.2, end = 0.8)(4)) -show_col(viridis_pal(option = "plasma")(6)) +show_col(pal_viridis()(10)) +show_col(pal_viridis(direction = -1)(6)) +show_col(pal_viridis(begin = 0.2, end = 0.8)(4)) +show_col(pal_viridis(option = "plasma")(6)) } \references{ \url{https://bids.github.io/colormap/} diff --git a/man/show_col.Rd b/man/show_col.Rd index e51c00f1..10c5c15d 100644 --- a/man/show_col.Rd +++ b/man/show_col.Rd @@ -23,10 +23,10 @@ possible.} A quick and dirty way to show colours in a plot. } \examples{ -show_col(hue_pal()(9)) -show_col(hue_pal()(9), borders = NA) +show_col(pal_hue()(9)) +show_col(pal_hue()(9), borders = NA) -show_col(viridis_pal()(16)) -show_col(viridis_pal()(16), labels = FALSE) +show_col(pal_viridis()(16)) +show_col(pal_viridis()(16), labels = FALSE) } \keyword{internal} diff --git a/tests/testthat/test-pal-hue.R b/tests/testthat/test-pal-hue.R index f50fd147..2ef2fdaa 100644 --- a/tests/testthat/test-pal-hue.R +++ b/tests/testthat/test-pal-hue.R @@ -1,19 +1,19 @@ -test_that("hue_pal arguments are forcely evaluated on each call #81", { - col1 <- hue_pal(h.start = 0) - col2 <- hue_pal(h.start = 90) +test_that("pal_hue arguments are forcely evaluated on each call #81", { + col1 <- pal_hue(h.start = 0) + col2 <- pal_hue(h.start = 90) colours <- list() hues <- c(0, 90) for (i in 1:2) { - colours[[i]] <- hue_pal(h.start = hues[i]) + colours[[i]] <- pal_hue(h.start = hues[i]) } expect_equal(col1(1), colours[[1]](1)) expect_equal(col2(1), colours[[2]](1)) }) test_that("hue_pal respects direction argument #252", { - col1 <- hue_pal() - col2 <- hue_pal(direction = -1) + col1 <- pal_hue() + col2 <- pal_hue(direction = -1) expect_equal(col1(3), rev(col2(3))) expect_equal(col1(9), rev(col2(9))) @@ -21,7 +21,7 @@ test_that("hue_pal respects direction argument #252", { test_that("hue_pal respects h.start", { hue <- function(...) { - farver::decode_colour(hue_pal(...)(2), to = "hcl")[, "h"] + farver::decode_colour(pal_hue(...)(2), to = "hcl")[, "h"] } # Have to use large tolerance since we're generating out of gamut colours. diff --git a/tests/testthat/test-pal-manual.R b/tests/testthat/test-pal-manual.R index 5b8acc17..d77e05a4 100644 --- a/tests/testthat/test-pal-manual.R +++ b/tests/testthat/test-pal-manual.R @@ -1,8 +1,8 @@ -test_that("manual_pal gives warning if n greater than the number of values", { - expect_warning(manual_pal(c("red", "blue", "green"))(4), "can handle a maximum") +test_that("pal_manual gives warning if n greater than the number of values", { + expect_warning(pal_manual(c("red", "blue", "green"))(4), "can handle a maximum") }) -test_that("manual_pal returns an unnamed vector", { +test_that("pal_manual returns an unnamed vector", { x <- c(foo = "red", bar = "blue") - expect_equal(manual_pal(x)(2), unname(x)) + expect_equal(pal_manual(x)(2), unname(x)) })