From 1c8b9ae15312442e3edf63d0a213c2195c9ddf9e Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 19 Dec 2024 17:23:03 +0000 Subject: [PATCH 1/8] Increment version number to 0.3.0.9000 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1819a56..ad75b6d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: sgplot Title: Graphic Styles and Colours for Scottish Government Plots -Version: 0.3.0 +Version: 0.3.0.9000 Authors@R: c( person("Scottish Government", , , "statistics.enquiries@gov.scot", role = c("cph", "fnd")), person("Alice", "Hannah", , "alice.hannah@gov.scot", c("aut", "cre")) diff --git a/NEWS.md b/NEWS.md index b0cb229..72b64f5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# sgplot (development version) + # sgplot 0.3.0 * Add Social Security Scotland colours (`sss_colour_values`) and palettes (`sss_colour_palettes`) From a090588fa531cf6ab4cb80db612eaff3e0ffc5ec Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 19 Dec 2024 17:36:33 +0000 Subject: [PATCH 2/8] Update Roxygen version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ad75b6d..0ff37d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ URL: BugReports: https://github.com/ScotGovAnalysis/sgplot/issues Encoding: UTF-8 LazyData: true -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Depends: R (>= 2.10) Imports: From fadef6abfcdb19e44c0cd767f08d56151a94560a Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 19 Dec 2024 17:59:27 +0000 Subject: [PATCH 3/8] Add fns to list and check available palettes/types --- NAMESPACE | 4 ++ R/utils-palettes.R | 82 +++++++++++++++++++++++++++++++++++++++ _pkgdown.yml | 2 + man/available_palettes.Rd | 25 ++++++++++++ man/check_palette.Rd | 27 +++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 R/utils-palettes.R create mode 100644 man/available_palettes.Rd create mode 100644 man/check_palette.Rd diff --git a/NAMESPACE b/NAMESPACE index c23d5b0..f3535d8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,9 @@ # Generated by roxygen2: do not edit by hand +export(available_palette_types) +export(available_palettes) +export(check_palette) +export(check_palette_type) export(mm_to_inch) export(scale_colour_continuous_sg) export(scale_colour_discrete_sg) diff --git a/R/utils-palettes.R b/R/utils-palettes.R new file mode 100644 index 0000000..a04d919 --- /dev/null +++ b/R/utils-palettes.R @@ -0,0 +1,82 @@ +#' @title Available palettes and palette types +#' +#' @param palette_type String. +#' +#' @return A character vector of available palettes or palette types. +#' +#' @examples +#' available_palette_types() +#' available_palettes("sg") +#' +#' @export + +available_palettes <- function(palette_type) { + + check_palette_type(palette_type) + + vec_name <- paste0("sgplot::", palette_type, "_colour_palettes") + + names(eval(parse(text = vec_name))) + +} + +#' @export +#' @rdname available_palettes + +available_palette_types <- function() { + + sgplot_data <- utils::data(package = "sgplot")$result[, "Item"] + + sgplot_palettes <- grep("_colour_palettes$", sgplot_data, value = TRUE) + + sub("_colour_palettes$", "", sgplot_palettes) + +} + + +#' @title Check palettes and palette types +#' +#' @description Checks values against those available in +#' `available_palette_types()` and `available_palettes()`. +#' +#' @param palette_type,palette String. +#' +#' @return The value being checked is returned invisibly if the check is +#' successful. Otherwise the function will return an error. +#' +#' @examples +#' check_palette_type("sg") +#' check_palette("sg", "main") +#' +#' @export + +check_palette <- function(palette_type, palette) { + + if (!palette %in% available_palettes(palette_type)) { + cli::cli_abort( + c("x" = paste("{.arg {palette}} is not an available", + "{.str {palette_type}} palette."), + "i" = paste("Available palette{?s}:", + "{.str {available_palettes(palette_type)}}.")) + ) + } else { + invisible(palette) + } + +} + +#' @export +#' @rdname check_palette + +check_palette_type <- function(palette_type) { + + if (!palette_type %in% available_palette_types()) { + cli::cli_abort( + c("x" = "{.arg {palette_type}} is not an available palette type.", + "i" = "Available palette type{?s}: {.str {available_palette_types()}}.") + ) + } else { + invisible(palette_type) + } + +} diff --git a/_pkgdown.yml b/_pkgdown.yml index af95f77..5f46fcb 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -73,6 +73,8 @@ reference: - title: Helpers contents: + - available_palettes + - check_palette - mm_to_inch figures: diff --git a/man/available_palettes.Rd b/man/available_palettes.Rd new file mode 100644 index 0000000..19dbc18 --- /dev/null +++ b/man/available_palettes.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-palettes.R +\name{available_palettes} +\alias{available_palettes} +\alias{available_palette_types} +\title{Available palettes and palette types} +\usage{ +available_palettes(palette_type) + +available_palette_types() +} +\arguments{ +\item{palette_type}{String.} +} +\value{ +A character vector of available palettes or palette types. +} +\description{ +Available palettes and palette types +} +\examples{ +available_palette_types() +available_palettes("sg") + +} diff --git a/man/check_palette.Rd b/man/check_palette.Rd new file mode 100644 index 0000000..a3455da --- /dev/null +++ b/man/check_palette.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-palettes.R +\name{check_palette} +\alias{check_palette} +\alias{check_palette_type} +\title{Check palettes and palette types} +\usage{ +check_palette(palette_type, palette) + +check_palette_type(palette_type) +} +\arguments{ +\item{palette_type, palette}{String.} +} +\value{ +The value being checked is returned invisibly if the check is +successful. Otherwise the function will return an error. +} +\description{ +Checks values against those available in +`available_palette_types()` and `available_palettes()`. +} +\examples{ +check_palette_type("sg") +check_palette("sg", "main") + +} From 980dae629d25e5f0996d38231303b9329fdade30 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Thu, 19 Dec 2024 18:41:34 +0000 Subject: [PATCH 4/8] Refactor sg_palette (closes #47) --- R/sg_palette.R | 142 +++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 69 deletions(-) diff --git a/R/sg_palette.R b/R/sg_palette.R index 30b86a2..5496ed9 100644 --- a/R/sg_palette.R +++ b/R/sg_palette.R @@ -1,94 +1,98 @@ -#' Return function to use Scottish Government colour palette +#' Return function to use sgplot colour palette #' #' @param palette Name of palette to use. #' @param reverse Boolean value to indicate whether the palette should be #' reversed. #' @param colour_names Boolean value to indicate whether colour names should be #' included. -#' @param palette_type Either "sg" to use Scottish Government palettes -#' (default), "sss" to use Social Security Scotland palettes or "af" to use -#' Analysis Function palettes. +#' @param palette_type Name of palette type to use. Defaults to "sg". For all +#' available palette types, run `available_palette_types()`. +#' +#' @return Function with one argument, `n`. #' #' @noRd sg_palette <- function(palette = "main", reverse = FALSE, colour_names = FALSE, - palette_type = c("sg", "sss", "af"), + palette_type = "sg", error_call = rlang::caller_env(), error_arg = rlang::caller_arg(palette)) { - palette_type <- rlang::arg_match(palette_type) + check_palette(palette_type, palette) - palette_list <- switch( - palette_type, - af = sgplot::af_colour_palettes, - sss = sgplot::sss_colour_palettes, - sg = sgplot::sg_colour_palettes - ) + function(n) { + pal <- get_colours(palette_type, palette, n) - # Check valid palette name - if (!palette %in% names(palette_list)) { - cli::cli_abort( - c("x" = paste("{.str {palette}} is not a valid palette name ", - "for {.str {palette_type}} palette type."), - "i" = "Available palette{?s}: {.str {names(palette_list)}}."), - call = error_call - ) + if (reverse) pal <- rev(pal) + + if (!colour_names) pal <- as.vector(pal) + + pal } - function(n) { - n_available <- length(palette_list[[palette]]) - - # Use 'main2' if AF main palette used and only 2 colours required - if ( - palette_type == "af" && - n == 2 && - palette != "main2" && - grepl("main", palette) - ) { - palette <- "main2" - cli::cli_warn(c( - "!" = "Using {.str main2} as only two colours are required." - )) - } - - ext_palettes <- subset( - names(palette_list), - stringr::str_detect(names(palette_list), "^main([5-9]|-extended)") - ) +} - # Error if more colours requested than exist in palette - if (n > n_available) { - cli::cli_abort( - c( - "x" = paste("{.arg {error_arg}} must contain at least", - "{n} colours."), - "i" = paste("The {.str {palette}} palette from the ", - "{.str {palette_type}} palette type", - "only contains {n_available} colours."), - if (n > 4) { - c("i" = paste("Accessibility guidance recommends a limit of four", - "colours per chart. If more than four colours are", - "required, first consider chart redesign.")) - }, - if (n > 4 & !is.null(ext_palettes)) { - c("i" = paste("If it is essential to use more than four colours,", - "the {.str {ext_palettes}} palette{?s} can be used.")) - } - ), - call = error_call - ) - } - pal <- palette_list[[palette]][seq_len(n)] +#' Get colours +#' +#' @description This function checks that the required number of colours are +#' available from the selected palette and palette type, and if so returns them. +#' If not, a helpful error is returned. +#' +#' @param palette_type,palette String. +#' @param n Number of colours required. +#' +#' @return Named character vector of colours, length `n`. +#' +#' @noRd - if (reverse) pal <- rev(pal) +get_colours <- function(palette_type, palette, n) { + + all_palettes <- eval(parse( + text = paste0("sgplot::", palette_type, "_colour_palettes") + )) - if (colour_names) { - pal - } else { - as.vector(pal) - } + n_available <- length(all_palettes[[palette]]) + + # Use 'main2' if AF main palette used and only 2 colours required + if ( + palette_type == "af" && + n == 2 && + palette != "main2" && + grepl("main", palette) + ) { + palette <- "main2" + cli::cli_warn(c( + "!" = "Using {.str main2} as only two colours are required." + )) } + + # Error if more colours requested than exist in palette + if (n > n_available) { + ext_palettes <- grep("^main([5-9]|-extended)", + available_palettes(palette_type), + value = TRUE) + + cli::cli_abort( + c( + "x" = "{.arg {palette}} must contain at least {n} colours.", + "i" = paste("The {.str {palette}} palette from the ", + "{.str {palette_type}} palette type", + "only contains {n_available} colours."), + if (n > 4) { + c("i" = paste("Accessibility guidance recommends a limit of four", + "colours per chart. If more than four colours are", + "required, first consider chart redesign.")) + }, + if (n > 4 & !is.null(ext_palettes)) { + c("i" = paste("If it is essential to use more than four colours,", + "the {.str {ext_palettes}} palette{?s} can be used.")) + } + ) + ) + } + + all_palettes[[palette]][seq_len(n)] + } From ff4a0d68bf6980249dffc513518149783abf4ca0 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 20 Dec 2024 09:41:53 +0000 Subject: [PATCH 5/8] Refactor sg_palette and utils tests --- tests/testthat/test-sg_palette.R | 76 +++++++++++++++++++--------- tests/testthat/test-utils-palettes.R | 25 +++++++++ 2 files changed, 76 insertions(+), 25 deletions(-) create mode 100644 tests/testthat/test-utils-palettes.R diff --git a/tests/testthat/test-sg_palette.R b/tests/testthat/test-sg_palette.R index a694c9c..519acdf 100644 --- a/tests/testthat/test-sg_palette.R +++ b/tests/testthat/test-sg_palette.R @@ -1,42 +1,68 @@ -test_that("Correct value returned", { + +# sg_palette ---- + +test_that("Returns function", { + expect_true(inherits(sg_palette(), "function")) +}) + +test_that("Function returns correct colours", { + expect_equal( - sg_palette()(4), - unname(sg_colour_palettes$main) + sg_palette()(2), + unname(sg_colour_palettes$main[seq_len(2)]) ) + expect_equal( - sg_palette(palette_type = "af")(4), - unname(af_colour_palettes$main) + sg_palette("focus", palette_type = "sss")(2), + unname(sss_colour_palettes$focus[seq_len(2)]) ) + +}) + +test_that("Palette reversed", { expect_equal( - sg_palette("main-extended", colour_names = TRUE)(5), - sg_colour_palettes$`main-extended`[1:5] + sg_palette(reverse = TRUE)(4), + unname(rev(sg_colour_palettes$main[seq_len(4)])) ) +}) + +test_that("Palette named", { expect_equal( - sg_palette("sequential", colour_names = TRUE)(3), - sg_colour_palettes$sequential + sg_palette(colour_names = TRUE)(4), + sg_colour_palettes$main[seq_len(4)] ) +}) + + +# get_colours ---- + +test_that("Correct colours returned", { + expect_equal( - sg_palette("focus", reverse = TRUE)(2), - unname(rev(sg_colour_palettes$focus)) + get_colours("sg", "main", 3), + sg_colour_palettes$main[seq_len(3)] ) -}) -test_that("Error if invalid palette name", { - expect_error(sg_palette("main2")(2)) - expect_error(sg_palette("af_main_palette")(2)) -}) + expect_equal( + get_colours("af", "sequential", 2), + af_colour_palettes$sequential[seq_len(2)] + ) -test_that("Error if too many colours requested", { - expect_error(sg_palette("main")(5)) - expect_error(sg_palette("sequential")(10)) - expect_error(sg_palette("focus")(3)) - expect_error(sg_palette("main", palette_type = "af")(5)) }) -test_that("Use `main2` if two colours required.", { - expect_warning(sg_palette("main", palette_type = "af")(2)) +test_that("Switch to `main2` for af if only 2 colours required", { + expect_equal( - suppressWarnings(sg_palette("main", palette_type = "af")(2)), - unname(af_colour_palettes$main2) + suppressWarnings(get_colours("af", "main", 2)), + af_colour_palettes$main2 ) + + expect_warning(get_colours("af", "main", 2)) + +}) + +test_that("Error if more colours requested than available", { + + expect_error(get_colours("sg", "main", 5)) + }) diff --git a/tests/testthat/test-utils-palettes.R b/tests/testthat/test-utils-palettes.R new file mode 100644 index 0000000..76f1596 --- /dev/null +++ b/tests/testthat/test-utils-palettes.R @@ -0,0 +1,25 @@ + +# available ---- + +test_that("Character vector returned", { + expect_type(available_palettes("sg"), "character") + expect_type(available_palette_types(), "character") +}) + + +# check ---- + +test_that("Invisible returned", { + expect_invisible(check_palette("sg", "main")) + expect_invisible(check_palette_type("sg")) +}) + +test_that("Correct value returned", { + expect_equal(check_palette("sg", "main"), "main") + expect_equal(check_palette_type("sg"), "sg") +}) + +test_that("Error if check doesn't pass", { + expect_error(check_palette("sg", "null")) + expect_error(check_palette_type("null")) +}) From 7178a2d3b514c9ce98e1cdebe2e68aa641c9ec23 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 20 Dec 2024 10:42:18 +0000 Subject: [PATCH 6/8] Allow n = NULL --- R/sg_palette.R | 2 ++ tests/testthat/test-sg_palette.R | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/R/sg_palette.R b/R/sg_palette.R index 5496ed9..eda6703 100644 --- a/R/sg_palette.R +++ b/R/sg_palette.R @@ -55,6 +55,8 @@ get_colours <- function(palette_type, palette, n) { n_available <- length(all_palettes[[palette]]) + if (is.null(n)) n <- n_available + # Use 'main2' if AF main palette used and only 2 colours required if ( palette_type == "af" && diff --git a/tests/testthat/test-sg_palette.R b/tests/testthat/test-sg_palette.R index 519acdf..43b9383 100644 --- a/tests/testthat/test-sg_palette.R +++ b/tests/testthat/test-sg_palette.R @@ -48,6 +48,11 @@ test_that("Correct colours returned", { af_colour_palettes$sequential[seq_len(2)] ) + expect_equal( + get_colours("sss", "main", n = NULL), + sss_colour_palettes$main + ) + }) test_that("Switch to `main2` for af if only 2 colours required", { From c1cb05030d6b4d733b5d188222b332e9c04c2cdb Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 20 Dec 2024 10:44:06 +0000 Subject: [PATCH 7/8] Remove options for pallete_type (closes #39) --- R/scale_continuous_sg.R | 50 ++++++++----------------------- R/scale_discrete_sg.R | 13 +++----- man/scale_colour_continuous_sg.Rd | 9 +++--- man/scale_colour_discrete_sg.Rd | 9 +++--- 4 files changed, 24 insertions(+), 57 deletions(-) diff --git a/R/scale_continuous_sg.R b/R/scale_continuous_sg.R index 3454d49..0b37868 100644 --- a/R/scale_continuous_sg.R +++ b/R/scale_continuous_sg.R @@ -20,30 +20,16 @@ #' @export scale_colour_continuous_sg <- function(palette = "sequential", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, na_colour = "grey50", guide = "colourbar", ...) { - palette_type <- match.arg(palette_type) - - palette_list <- switch( - palette_type, - af = sgplot::af_colour_palettes, - sg = sgplot::sg_colour_palettes, - sss = sgplot::sss_colour_palettes - ) - - # Error if palette doesn't exist - if (!palette %in% names(palette_list)) { - cli::cli_abort(c( - "x" = paste("`{palette}` is not a valid palette name in", - "`{palette_type}_colour_palettes`.") - )) - } - - colours <- as.vector(palette_list[[palette]]) + colours <- + sg_palette(palette = palette, + palette_type = palette_type, + reverse = reverse)(n = NULL) ggplot2::continuous_scale( aesthetics = "colour", @@ -52,36 +38,23 @@ scale_colour_continuous_sg <- function(palette = "sequential", guide = guide, ... ) + } #' @export #' @rdname scale_colour_continuous_sg scale_fill_continuous_sg <- function(palette = "sequential", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, na_colour = "grey50", guide = "colourbar", ...) { - palette_type <- match.arg(palette_type) - - palette_list <- switch( - palette_type, - af = sgplot::af_colour_palettes, - sg = sgplot::sg_colour_palettes, - sss = sgplot::sss_colour_palettes - ) - - # Error if palette doesn't exist - if (!palette %in% names(palette_list)) { - cli::cli_abort(c( - "x" = paste("`{palette}` is not a valid palette name in", - "`{palette_type}_colour_palettes`.") - )) - } - - colours <- as.vector(palette_list[[palette]]) + colours <- + sg_palette(palette = palette, + palette_type = palette_type, + reverse = reverse)(n = NULL) ggplot2::continuous_scale( aesthetics = "fill", @@ -90,4 +63,5 @@ scale_fill_continuous_sg <- function(palette = "sequential", guide = guide, ... ) + } diff --git a/R/scale_discrete_sg.R b/R/scale_discrete_sg.R index 9c1e180..9155885 100644 --- a/R/scale_discrete_sg.R +++ b/R/scale_discrete_sg.R @@ -2,9 +2,8 @@ #' #' @param palette Name of palette to use; e.g. "main", "sequential", "focus". #' Default value is "main". -#' @param palette_type Either "sg" to use Scottish Government palettes -#' (default), "sss" to use Social Security Scotland palettes or "af" to use -#' Analysis Function palettes. +#' @param palette_type Name of palette type to use. Defaults to "sg". For all +#' available palette types, run `available_palette_types()`. #' @param reverse Boolean value to indicate whether the palette should be #' reversed. #' @param ... Additional arguments passed to scale type. @@ -28,12 +27,10 @@ #' @export scale_colour_discrete_sg <- function(palette = "main", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, ...) { - palette_type <- match.arg(palette_type) - ggplot2::discrete_scale( aesthetics = "colour", palette = sg_palette(palette, reverse, palette_type = palette_type), @@ -47,12 +44,10 @@ scale_colour_discrete_sg <- function(palette = "main", #' @rdname scale_colour_discrete_sg scale_fill_discrete_sg <- function(palette = "main", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, ...) { - palette_type <- match.arg(palette_type) - ggplot2::discrete_scale( aesthetics = "fill", palette = sg_palette(palette, reverse, palette_type = palette_type), diff --git a/man/scale_colour_continuous_sg.Rd b/man/scale_colour_continuous_sg.Rd index 425b2c6..f737184 100644 --- a/man/scale_colour_continuous_sg.Rd +++ b/man/scale_colour_continuous_sg.Rd @@ -7,7 +7,7 @@ \usage{ scale_colour_continuous_sg( palette = "sequential", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, na_colour = "grey50", guide = "colourbar", @@ -16,7 +16,7 @@ scale_colour_continuous_sg( scale_fill_continuous_sg( palette = "sequential", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, na_colour = "grey50", guide = "colourbar", @@ -27,9 +27,8 @@ scale_fill_continuous_sg( \item{palette}{Name of palette to use; e.g. "main", "sequential", "focus". Default value is "sequential".} -\item{palette_type}{Either "sg" to use Scottish Government palettes -(default), "sss" to use Social Security Scotland palettes or "af" to use -Analysis Function palettes.} +\item{palette_type}{Name of palette type to use. Defaults to "sg". For all +available palette types, run `available_palette_types()`.} \item{reverse}{Boolean value to indicate whether the palette should be reversed.} diff --git a/man/scale_colour_discrete_sg.Rd b/man/scale_colour_discrete_sg.Rd index ac1f512..d16a556 100644 --- a/man/scale_colour_discrete_sg.Rd +++ b/man/scale_colour_discrete_sg.Rd @@ -7,14 +7,14 @@ \usage{ scale_colour_discrete_sg( palette = "main", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, ... ) scale_fill_discrete_sg( palette = "main", - palette_type = c("sg", "sss", "af"), + palette_type = "sg", reverse = FALSE, ... ) @@ -23,9 +23,8 @@ scale_fill_discrete_sg( \item{palette}{Name of palette to use; e.g. "main", "sequential", "focus". Default value is "main".} -\item{palette_type}{Either "sg" to use Scottish Government palettes -(default), "sss" to use Social Security Scotland palettes or "af" to use -Analysis Function palettes.} +\item{palette_type}{Name of palette type to use. Defaults to "sg". For all +available palette types, run `available_palette_types()`.} \item{reverse}{Boolean value to indicate whether the palette should be reversed.} From d21cac159310815827ca043a646c6d604c8ee740 Mon Sep 17 00:00:00 2001 From: alice-hannah Date: Fri, 20 Dec 2024 10:59:42 +0000 Subject: [PATCH 8/8] Fix lintr warning --- R/sg_palette.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/sg_palette.R b/R/sg_palette.R index eda6703..ea9428f 100644 --- a/R/sg_palette.R +++ b/R/sg_palette.R @@ -60,9 +60,9 @@ get_colours <- function(palette_type, palette, n) { # Use 'main2' if AF main palette used and only 2 colours required if ( palette_type == "af" && - n == 2 && - palette != "main2" && - grepl("main", palette) + n == 2 && + palette != "main2" && + grepl("main", palette) ) { palette <- "main2" cli::cli_warn(c(