diff --git a/CITATION.cff b/CITATION.cff index a0a1710f..61e7cd26 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -8,7 +8,7 @@ message: 'To cite package "tidyBdE" in publications use:' type: software license: GPL-3.0-or-later title: 'tidyBdE: Download Data from Bank of Spain' -version: 0.3.4 +version: 0.3.4.9000 doi: 10.5281/zenodo.4673496 abstract: Tools to download data series from 'Banco de España' ('BdE') on 'tibble' format. 'Banco de España' is the national central bank and, within the framework @@ -32,7 +32,7 @@ preferred-citation: affiliation: rOpenSpain doi: 10.5281/zenodo.4673496 year: '2024' - version: 0.3.4 + version: 0.3.4.9000 url: https://ropenspain.github.io/tidyBdE/ abstract: Tools to download data series from Banco de España (BdE) on tibble format. Banco de España is the national central bank and, within the framework of the @@ -134,6 +134,21 @@ references: orcid: https://orcid.org/0000-0002-9415-4582 year: '2024' version: '>= 3.3.0' +- type: software + title: lifecycle + abstract: 'lifecycle: Manage the Life Cycle of your Package Functions' + notes: Imports + url: https://lifecycle.r-lib.org/ + repository: https://CRAN.R-project.org/package=lifecycle + authors: + - family-names: Henry + given-names: Lionel + email: lionel@posit.co + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + orcid: https://orcid.org/0000-0003-4757-117X + year: '2024' - type: software title: readr abstract: 'readr: Read Rectangular Text Data' diff --git a/DESCRIPTION b/DESCRIPTION index 28760195..841c7825 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidyBdE Title: Download Data from Bank of Spain -Version: 0.3.4 +Version: 0.3.4.9000 Authors@R: person("Diego", "H. Herrero", , "dev.dieghernan@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0001-8457-4658", affiliation = "rOpenSpain")) @@ -19,6 +19,7 @@ Depends: Imports: dplyr (>= 0.7.0), ggplot2 (>= 3.3.0), + lifecycle, readr (>= 1.0.0), scales (>= 1.1.0), tibble (>= 3.0.0), @@ -37,6 +38,6 @@ Config/testthat/parallel: true Copyright: See file inst/COPYRIGHTS Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.0 +RoxygenNote: 7.3.1 X-schema.org-applicationCategory: Macroeconomics X-schema.org-isPartOf: https://ropenspain.es/ diff --git a/NAMESPACE b/NAMESPACE index 3b65c154..07e1b10b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(bde_ind_ibex_daily) export(bde_ind_ibex_monthly) export(bde_ind_population) export(bde_ind_unemployment_rate) +export(bde_palettes) export(bde_parse_dates) export(bde_rose_pal) export(bde_series_full_load) @@ -21,6 +22,8 @@ export(bde_series_load) export(bde_vivid_pal) export(scale_color_bde_c) export(scale_color_bde_d) +export(scale_colour_bde_c) +export(scale_colour_bde_d) export(scale_fill_bde_c) export(scale_fill_bde_d) export(theme_tidybde) @@ -32,5 +35,7 @@ importFrom(ggplot2,element_text) importFrom(ggplot2,margin) importFrom(ggplot2,rel) importFrom(ggplot2,unit) +importFrom(lifecycle,deprecated) +importFrom(tibble,tibble) importFrom(utils,download.file) importFrom(utils,read.csv2) diff --git a/NEWS.md b/NEWS.md index 90d3f6bc..f419022a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# tidyBdE (development version) + +- `bde_vivid_pal()` and `bde_rose_pal()` have been deprecated. Use the new +function `bde_palettes()` instead. + # tidyBdE 0.3.4 - Update API entry points. diff --git a/R/bde_palettes.R b/R/bde_palettes.R new file mode 100644 index 00000000..caf79a88 --- /dev/null +++ b/R/bde_palettes.R @@ -0,0 +1,59 @@ +#' BdE color palettes +#' +#' Custom palettes based on the publications of BdE. These are manual palettes +#' with a maximum of 6 colors. +#' +#' @family bde_plot +#' +#' +#' @return A vector of colors. +#' +#' @export +#' @param n The number of colors (`>= 1`) to be in the palette. +#' @param palette A valid palette name. +#' @param alpha An alpha-transparency level in the range `[0,1]` (`0` means +#' transparent and `1` means opaque). A missing, i.e., `alpha = NULL`, does +#' not add opacity codes (`"FF"`) to the individual color hex codes. See +#' [ggplot2::alpha()]. +#' @param rev Logical indicating whether the ordering of the colors should be +#' reversed. +#' @examples +#' +#' # BdE vivid pal +#' scales::show_col(bde_palettes(palette = "bde_vivid_pal"), labels = FALSE) +#' +#' # BdE rose pal +#' scales::show_col(bde_palettes(palette = "bde_rose_pal"), labels = FALSE) +bde_palettes <- function(n = 6, palette = c("bde_vivid_pal", "bde_rose_pal"), + alpha = NULL, rev = FALSE) { + palette <- match.arg(palette) + + cols <- switch(palette, + "bde_vivid_pal" = c( + "#4180C2", "#D86E7B", "#F89E63", + "#5FBD6A", "#62C8D0", "#AC8771" + ), + "bde_rose_pal" = c( + "#b7365c", "#cb6e8a", "#db9aad", + "#0a50a1", "#5385bd", "#89AEDA" + ) + ) + + n_col <- length(cols) + if (n > n_col) { + message( + "tidyBdE> ", palette, " has ", n_col, ", requested ", n, + ". Returning ", n_col, " colors." + ) + + n <- n_col + } + + endcols <- cols[seq_len(n)] + + # Options + if (rev) endcols <- rev(endcols) + if (!is.null(alpha)) endcols <- ggplot2::alpha(endcols, alpha) + + return(endcols) +} diff --git a/R/catalogs.R b/R/catalogs.R index 9ac657f2..cb07583a 100644 --- a/R/catalogs.R +++ b/R/catalogs.R @@ -10,7 +10,8 @@ #' @return A `tibble`. #' #' -#' @source [Time-series bulk data +#' @source +#' [Time-series bulk data #' download](https://www.bde.es/webbe/en/estadisticas/recursos/descargas-completas.html) #' #' @param catalog A single value indicating the catalogs to be updated @@ -208,7 +209,8 @@ bde_catalog_load <- #' #' @return None. Downloads the catalog file(s) to the local machine. #' -#' @source [Time-series bulk data +#' @source +#' [Time-series bulk data #' download](https://www.bde.es/webbe/en/estadisticas/recursos/descargas-completas.html) #' #' @param catalog A vector of characters indicating the catalogs to be updated diff --git a/R/bde_pals.R b/R/deprecated.R similarity index 64% rename from R/bde_pals.R rename to R/deprecated.R index 127bda1d..513be3e3 100644 --- a/R/bde_pals.R +++ b/R/deprecated.R @@ -1,20 +1,19 @@ -#' BdE color palettes +#' BdE superseeded palettes #' -#' Custom palettes based on the publications of BdE. +#' @description +#' `r lifecycle::badge('deprecated')` See [bde_palettes()] #' -#' @family bde_plot -#' -#' @rdname bde_pals -#' @name bde_pals #' #' @return A palette of colors. #' -#' @export #' #' @param ... Further arguments of the functions. #' +#' @name bde_vivid_pal +#' @rdname bde_pals #' -#' +#' @export +#' @keywords internal #' @examples #' #' # BdE vivid pal @@ -23,18 +22,24 @@ #' # BdE rose pal #' scales::show_col(bde_rose_pal()(6), labels = FALSE) bde_vivid_pal <- function(...) { - # nocov start + lifecycle::deprecate_warn( + "0.3.4", "bde_vivid_pal()", + "bde_palettes()" + ) + pal <- c("#4180C2", "#D86E7B", "#F89E63", "#5FBD6A", "#62C8D0", "#AC8771") return(scales::manual_pal(pal)) - # nocov end } #' @rdname bde_pals -#' +#' @keywords internal #' @export bde_rose_pal <- function(...) { - # nocov start + lifecycle::deprecate_warn( + "0.3.4", "bde_rose_pal()", + "bde_palettes()" + ) + pal <- c("#b7365c", "#cb6e8a", "#db9aad", "#0a50a1", "#5385bd", "#89AEDA") return(scales::manual_pal(pal)) - # nocov end } diff --git a/R/scales.R b/R/scales.R index a357c4ed..7825f181 100644 --- a/R/scales.R +++ b/R/scales.R @@ -1,25 +1,24 @@ -#' BdE scales for `ggplot2`. +#' BdE scales for \CRANpkg{ggplot2}. #' #' @description #' #' Scales to be used with the \CRANpkg{ggplot2} package. Discrete palettes are #' named as `scale_*_bde_d` while continuous palettes are named `scale_*_bde_c`. #' -#' @seealso [bde_vivid_pal()], [ggplot2::discrete_scale()], -#' [ggplot2::continuous_scale()] +#' @seealso [ggplot2::discrete_scale()], [ggplot2::continuous_scale()] #' #' @family bde_plot #' #' @export #' -#' @return A `ggplot2` color scale. +#' @return A \CRANpkg{ggplot2} color scale. #' #' @rdname scales_bde #' #' @name scales_bde #' #' @param palette Name of the BdE palette to apply. One of `"bde_vivid_pal"`, -#' `"bde_rose_pal"`. See [bde_pals()] for details. +#' `"bde_rose_pal"`. See [bde_palettes()] for details. #' #' @param ... Further arguments of [ggplot2::discrete_scale()] or #' [ggplot2::continuous_scale()]. @@ -48,69 +47,56 @@ #' theme_minimal() #' scale_color_bde_d <- function(palette = c("bde_vivid_pal", "bde_rose_pal"), - ...) { # nocov start - + ...) { palette <- match.arg(palette) - valid_pals <- c("bde_vivid_pal", "bde_rose_pal") - if (!palette %in% valid_pals) { - stop("palette should be one of: ", paste0(valid_pals, collapse = ", ")) - } + cols_v <- bde_palettes(palette = palette) + pal <- scales::manual_pal(cols_v) - cols <- switch(palette, - "bde_vivid_pal" = bde_vivid_pal(), - "bde_rose_pal" = bde_rose_pal() - ) ggplot2::discrete_scale( aesthetics = "color", + palette = pal, scale_name = palette, - palette = cols, ... ) - # nocov end } +#' @rdname scales_bde +#' @name scales_bde +#' @export +#' @usage NULL +scale_colour_bde_d <- scale_color_bde_d + #' @rdname scales_bde #' @name scales_bde #' @export scale_fill_bde_d <- function(palette = c("bde_vivid_pal", "bde_rose_pal"), - ...) { # nocov start + ...) { palette <- match.arg(palette) - valid_pals <- c("bde_vivid_pal", "bde_rose_pal") - if (!palette %in% valid_pals) { - stop("palette should be one of :", paste0(valid_pals, collapse = ", ")) - } + cols_v <- bde_palettes(palette = palette) + pal <- scales::manual_pal(cols_v) - cols <- switch(palette, - "bde_vivid_pal" = bde_vivid_pal(), - "bde_rose_pal" = bde_rose_pal() - ) ggplot2::discrete_scale( aesthetics = "fill", + palette = pal, scale_name = palette, - palette = cols, ... ) - # nocov end } #' @rdname scales_bde #' @name scales_bde #' @export -scale_color_bde_c <- function(palette = c("bde_vivid_pal", "bde_rose_pal"), - ...) { # nocov start +scale_color_bde_c <- function(palette = c("bde_rose_pal", "bde_vivid_pal"), + ...) { palette <- match.arg(palette) - valid_pals <- c("bde_vivid_pal", "bde_rose_pal") - if (!palette %in% valid_pals) { - stop("palette should be one of :", paste0(valid_pals, collapse = ", ")) - } cols <- switch(palette, - "bde_vivid_pal" = bde_vivid_pal()(6), - "bde_rose_pal" = c(bde_rose_pal()(6)[1:3], bde_rose_pal()(6)[6:4]) + "bde_vivid_pal" = bde_palettes(6, "bde_vivid_pal"), + "bde_rose_pal" = bde_palettes(6, "bde_rose_pal")[c(1, 2, 3, 6, 5, 4)] ) ggplot2::continuous_scale( aesthetics = "color", @@ -118,24 +104,25 @@ scale_color_bde_c <- function(palette = c("bde_vivid_pal", "bde_rose_pal"), palette = scales::gradient_n_pal(cols), ... ) - # nocov end } #' @rdname scales_bde #' @name scales_bde #' @export -scale_fill_bde_c <- function(palette = c("bde_vivid_pal", "bde_rose_pal"), - ...) { # nocov start +#' @usage NULL +scale_colour_bde_c <- scale_color_bde_c + +#' @rdname scales_bde +#' @name scales_bde +#' @export +scale_fill_bde_c <- function(palette = c("bde_rose_pal", "bde_vivid_pal"), + ...) { palette <- match.arg(palette) - valid_pals <- c("bde_vivid_pal", "bde_rose_pal") - if (!palette %in% valid_pals) { - stop("palette should be one of :", paste0(valid_pals, collapse = ", ")) - } cols <- switch(palette, - "bde_vivid_pal" = bde_vivid_pal()(6), - "bde_rose_pal" = c(bde_rose_pal()(6)[1:3], bde_rose_pal()(6)[6:4]) + "bde_vivid_pal" = bde_palettes(6, "bde_vivid_pal"), + "bde_rose_pal" = bde_palettes(6, "bde_rose_pal")[c(1, 2, 3, 6, 5, 4)] ) ggplot2::continuous_scale( aesthetics = "fill", @@ -143,5 +130,4 @@ scale_fill_bde_c <- function(palette = c("bde_vivid_pal", "bde_rose_pal"), palette = scales::gradient_n_pal(cols), ... ) - # nocov end } diff --git a/R/tidyBdE-package.R b/R/tidyBdE-package.R index 1bb155b3..107309cd 100644 --- a/R/tidyBdE-package.R +++ b/R/tidyBdE-package.R @@ -4,10 +4,12 @@ # The following block is used by usethis to automatically manage # roxygen namespace tags. Modify with care! ## usethis namespace: start +#' @importFrom lifecycle deprecated ## usethis namespace: end NULL # import stuffs #' @importFrom utils download.file read.csv2 +#' @importFrom tibble tibble #' @importFrom ggplot2 unit element_rect element_text element_blank element_line NULL diff --git a/README.md b/README.md index 73e75af3..fbe04d14 100644 --- a/README.md +++ b/README.md @@ -244,7 +244,7 @@ A BibTeX entry for LaTeX users is doi = {10.5281/zenodo.4673496}, author = {Diego {H. Herrero}}, year = {2024}, - version = {0.3.4}, + version = {0.3.4.9000}, url = {https://ropenspain.github.io/tidyBdE/}, abstract = {Tools to download data series from Banco de España (BdE) on tibble format. Banco de España is the national central bank and, within the framework of the Single Supervisory Mechanism (SSM), the supervisor of the Spanish banking system along with the European Central Bank. This package is in no way sponsored endorsed or administered by Banco de España.}, } diff --git a/codemeta.json b/codemeta.json index cec6ef46..c4cfb1ae 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/rOpenSpain/tidyBdE", "issueTracker": "https://github.com/rOpenSpain/tidyBdE/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.3.4", + "version": "0.3.4.9000", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", @@ -121,6 +121,18 @@ "sameAs": "https://CRAN.R-project.org/package=ggplot2" }, "4": { + "@type": "SoftwareApplication", + "identifier": "lifecycle", + "name": "lifecycle", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=lifecycle" + }, + "5": { "@type": "SoftwareApplication", "identifier": "readr", "name": "readr", @@ -133,7 +145,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=readr" }, - "5": { + "6": { "@type": "SoftwareApplication", "identifier": "scales", "name": "scales", @@ -146,7 +158,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=scales" }, - "6": { + "7": { "@type": "SoftwareApplication", "identifier": "tibble", "name": "tibble", @@ -159,7 +171,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=tibble" }, - "7": { + "8": { "@type": "SoftwareApplication", "identifier": "tidyr", "name": "tidyr", @@ -171,7 +183,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=tidyr" }, - "8": { + "9": { "@type": "SoftwareApplication", "identifier": "utils", "name": "utils" @@ -180,7 +192,7 @@ }, "applicationCategory": "Macroeconomics", "isPartOf": "https://ropenspain.es/", - "fileSize": "271.755KB", + "fileSize": "290.036KB", "citation": [ { "@type": "SoftwareSourceCode", diff --git a/inst/schemaorg.json b/inst/schemaorg.json index 2a516674..f8803807 100644 --- a/inst/schemaorg.json +++ b/inst/schemaorg.json @@ -29,7 +29,7 @@ "url": "https://cran.r-project.org" }, "runtimePlatform": "R version 4.3.2 (2023-10-31 ucrt)", - "version": "0.3.4" + "version": "0.3.4.9000" }, { "id": "https://doi.org/10.5281/zenodo.4673496", diff --git a/man/bde_palettes.Rd b/man/bde_palettes.Rd new file mode 100644 index 00000000..a1486296 --- /dev/null +++ b/man/bde_palettes.Rd @@ -0,0 +1,47 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bde_palettes.R +\name{bde_palettes} +\alias{bde_palettes} +\title{BdE color palettes} +\usage{ +bde_palettes( + n = 6, + palette = c("bde_vivid_pal", "bde_rose_pal"), + alpha = NULL, + rev = FALSE +) +} +\arguments{ +\item{n}{The number of colors (\verb{>= 1}) to be in the palette.} + +\item{palette}{A valid palette name.} + +\item{alpha}{An alpha-transparency level in the range \verb{[0,1]} (\code{0} means +transparent and \code{1} means opaque). A missing, i.e., \code{alpha = NULL}, does +not add opacity codes (\code{"FF"}) to the individual color hex codes. See +\code{\link[ggplot2:reexports]{ggplot2::alpha()}}.} + +\item{rev}{Logical indicating whether the ordering of the colors should be +reversed.} +} +\value{ +A vector of colors. +} +\description{ +Custom palettes based on the publications of BdE. These are manual palettes +with a maximum of 6 colors. +} +\examples{ + +# BdE vivid pal +scales::show_col(bde_palettes(palette = "bde_vivid_pal"), labels = FALSE) + +# BdE rose pal +scales::show_col(bde_palettes(palette = "bde_rose_pal"), labels = FALSE) +} +\seealso{ +Other bde_plot: +\code{\link{scales_bde}}, +\code{\link{theme_tidybde}()} +} +\concept{bde_plot} diff --git a/man/bde_pals.Rd b/man/bde_pals.Rd index 77244443..a84f71f6 100644 --- a/man/bde_pals.Rd +++ b/man/bde_pals.Rd @@ -1,10 +1,9 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/bde_pals.R -\name{bde_pals} -\alias{bde_pals} +% Please edit documentation in R/deprecated.R +\name{bde_vivid_pal} \alias{bde_vivid_pal} \alias{bde_rose_pal} -\title{BdE color palettes} +\title{BdE superseeded palettes} \usage{ bde_vivid_pal(...) @@ -17,7 +16,7 @@ bde_rose_pal(...) A palette of colors. } \description{ -Custom palettes based on the publications of BdE. +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} See \code{\link[=bde_palettes]{bde_palettes()}} } \examples{ @@ -27,9 +26,4 @@ scales::show_col(bde_vivid_pal()(6), labels = FALSE) # BdE rose pal scales::show_col(bde_rose_pal()(6), labels = FALSE) } -\seealso{ -Other bde_plot: -\code{\link{scales_bde}}, -\code{\link{theme_tidybde}()} -} -\concept{bde_plot} +\keyword{internal} diff --git a/man/figures/lifecycle-archived.svg b/man/figures/lifecycle-archived.svg new file mode 100644 index 00000000..745ab0c7 --- /dev/null +++ b/man/figures/lifecycle-archived.svg @@ -0,0 +1,21 @@ + + lifecycle: archived + + + + + + + + + + + + + + + lifecycle + + archived + + diff --git a/man/figures/lifecycle-defunct.svg b/man/figures/lifecycle-defunct.svg new file mode 100644 index 00000000..d5c9559e --- /dev/null +++ b/man/figures/lifecycle-defunct.svg @@ -0,0 +1,21 @@ + + lifecycle: defunct + + + + + + + + + + + + + + + lifecycle + + defunct + + diff --git a/man/figures/lifecycle-deprecated.svg b/man/figures/lifecycle-deprecated.svg new file mode 100644 index 00000000..b61c57c3 --- /dev/null +++ b/man/figures/lifecycle-deprecated.svg @@ -0,0 +1,21 @@ + + lifecycle: deprecated + + + + + + + + + + + + + + + lifecycle + + deprecated + + diff --git a/man/figures/lifecycle-experimental.svg b/man/figures/lifecycle-experimental.svg new file mode 100644 index 00000000..5d88fc2c --- /dev/null +++ b/man/figures/lifecycle-experimental.svg @@ -0,0 +1,21 @@ + + lifecycle: experimental + + + + + + + + + + + + + + + lifecycle + + experimental + + diff --git a/man/figures/lifecycle-maturing.svg b/man/figures/lifecycle-maturing.svg new file mode 100644 index 00000000..897370ec --- /dev/null +++ b/man/figures/lifecycle-maturing.svg @@ -0,0 +1,21 @@ + + lifecycle: maturing + + + + + + + + + + + + + + + lifecycle + + maturing + + diff --git a/man/figures/lifecycle-questioning.svg b/man/figures/lifecycle-questioning.svg new file mode 100644 index 00000000..7c1721d0 --- /dev/null +++ b/man/figures/lifecycle-questioning.svg @@ -0,0 +1,21 @@ + + lifecycle: questioning + + + + + + + + + + + + + + + lifecycle + + questioning + + diff --git a/man/figures/lifecycle-soft-deprecated.svg b/man/figures/lifecycle-soft-deprecated.svg new file mode 100644 index 00000000..9c166ff3 --- /dev/null +++ b/man/figures/lifecycle-soft-deprecated.svg @@ -0,0 +1,21 @@ + + lifecycle: soft-deprecated + + + + + + + + + + + + + + + lifecycle + + soft-deprecated + + diff --git a/man/figures/lifecycle-stable.svg b/man/figures/lifecycle-stable.svg new file mode 100644 index 00000000..9bf21e76 --- /dev/null +++ b/man/figures/lifecycle-stable.svg @@ -0,0 +1,29 @@ + + lifecycle: stable + + + + + + + + + + + + + + + + lifecycle + + + + stable + + + diff --git a/man/figures/lifecycle-superseded.svg b/man/figures/lifecycle-superseded.svg new file mode 100644 index 00000000..db8d757f --- /dev/null +++ b/man/figures/lifecycle-superseded.svg @@ -0,0 +1,21 @@ + + lifecycle: superseded + + + + + + + + + + + + + + + lifecycle + + superseded + + diff --git a/man/figures/logo.png b/man/figures/logo.png index 6ebb0b38..5b9f94fe 100644 Binary files a/man/figures/logo.png and b/man/figures/logo.png differ diff --git a/man/scales_bde.Rd b/man/scales_bde.Rd index 1963132f..70282f6b 100644 --- a/man/scales_bde.Rd +++ b/man/scales_bde.Rd @@ -3,28 +3,30 @@ \name{scales_bde} \alias{scales_bde} \alias{scale_color_bde_d} +\alias{scale_colour_bde_d} \alias{scale_fill_bde_d} \alias{scale_color_bde_c} +\alias{scale_colour_bde_c} \alias{scale_fill_bde_c} -\title{BdE scales for \code{ggplot2}.} +\title{BdE scales for \CRANpkg{ggplot2}.} \usage{ scale_color_bde_d(palette = c("bde_vivid_pal", "bde_rose_pal"), ...) scale_fill_bde_d(palette = c("bde_vivid_pal", "bde_rose_pal"), ...) -scale_color_bde_c(palette = c("bde_vivid_pal", "bde_rose_pal"), ...) +scale_color_bde_c(palette = c("bde_rose_pal", "bde_vivid_pal"), ...) -scale_fill_bde_c(palette = c("bde_vivid_pal", "bde_rose_pal"), ...) +scale_fill_bde_c(palette = c("bde_rose_pal", "bde_vivid_pal"), ...) } \arguments{ \item{palette}{Name of the BdE palette to apply. One of \code{"bde_vivid_pal"}, -\code{"bde_rose_pal"}. See \code{\link[=bde_pals]{bde_pals()}} for details.} +\code{"bde_rose_pal"}. See \code{\link[=bde_palettes]{bde_palettes()}} for details.} \item{...}{Further arguments of \code{\link[ggplot2:discrete_scale]{ggplot2::discrete_scale()}} or \code{\link[ggplot2:continuous_scale]{ggplot2::continuous_scale()}}.} } \value{ -A \code{ggplot2} color scale. +A \CRANpkg{ggplot2} color scale. } \description{ Scales to be used with the \CRANpkg{ggplot2} package. Discrete palettes are @@ -55,11 +57,10 @@ ggplot(txsamp, aes(x = sales, y = median)) + } \seealso{ -\code{\link[=bde_vivid_pal]{bde_vivid_pal()}}, \code{\link[ggplot2:discrete_scale]{ggplot2::discrete_scale()}}, -\code{\link[ggplot2:continuous_scale]{ggplot2::continuous_scale()}} +\code{\link[ggplot2:discrete_scale]{ggplot2::discrete_scale()}}, \code{\link[ggplot2:continuous_scale]{ggplot2::continuous_scale()}} Other bde_plot: -\code{\link{bde_pals}}, +\code{\link{bde_palettes}()}, \code{\link{theme_tidybde}()} } \concept{bde_plot} diff --git a/man/theme_tidybde.Rd b/man/theme_tidybde.Rd index 0f4d82a8..1c83ef8e 100644 --- a/man/theme_tidybde.Rd +++ b/man/theme_tidybde.Rd @@ -62,7 +62,7 @@ if (nrow(series_TC) > 0) { \code{\link[ggplot2:ggtheme]{ggplot2::theme_classic()}} Other bde_plot: -\code{\link{bde_pals}}, +\code{\link{bde_palettes}()}, \code{\link{scales_bde}} } \concept{bde_plot} diff --git a/tests/testthat/_snaps/bde_col_pal.md b/tests/testthat/_snaps/bde_col_pal.md new file mode 100644 index 00000000..5bafde06 --- /dev/null +++ b/tests/testthat/_snaps/bde_col_pal.md @@ -0,0 +1,15 @@ +# Test error + + Code + bde_palettes(palette = "none") + Condition + Error in `match.arg()`: + ! 'arg' should be one of "bde_vivid_pal", "bde_rose_pal" + +# Max value + + Code + nmore <- bde_palettes(n = 23) + Message + tidyBdE> bde_vivid_pal has 6, requested 23. Returning 6 colors. + diff --git a/tests/testthat/_snaps/deprecated.md b/tests/testthat/_snaps/deprecated.md new file mode 100644 index 00000000..76811131 --- /dev/null +++ b/tests/testthat/_snaps/deprecated.md @@ -0,0 +1,18 @@ +# bde_vivid_pal + + Code + vpal <- bde_vivid_pal()(3) + Condition + Warning: + `bde_vivid_pal()` was deprecated in tidyBdE 0.3.4. + i Please use `bde_palettes()` instead. + +# bde_rose_pal + + Code + vpal <- bde_rose_pal()(4) + Condition + Warning: + `bde_rose_pal()` was deprecated in tidyBdE 0.3.4. + i Please use `bde_palettes()` instead. + diff --git a/tests/testthat/test-bde_palettes.R b/tests/testthat/test-bde_palettes.R new file mode 100644 index 00000000..1b39c7a8 --- /dev/null +++ b/tests/testthat/test-bde_palettes.R @@ -0,0 +1,46 @@ +test_that("Test error", { + expect_snapshot(bde_palettes(palette = "none"), + error = TRUE + ) +}) + + +test_that("Max value", { + ok <- bde_palettes(n = 6) + + expect_snapshot(nmore <- bde_palettes(n = 23)) + + expect_identical(ok, nmore) +}) + + +test_that("Switch pal", { + ok <- bde_palettes(n = 6) + other <- bde_palettes(n = 6, palette = "bde_rose_pal") + + expect_false(any(ok == other)) +}) + + + +test_that("test n", { + ok <- bde_palettes(n = 6) + ok3 <- bde_palettes(n = 3) + + expect_identical(ok[seq_len(3)], ok3) +}) + + +test_that("test rev", { + ok <- bde_palettes(n = 6) + ok3 <- bde_palettes(n = 3, rev = TRUE) + + expect_identical(ok[rev(seq_len(3))], ok3) +}) + +test_that("test alpha", { + ok <- bde_palettes(n = 6) + ok3 <- bde_palettes(n = 6, alpha = 0.2) + + expect_identical(ggplot2::alpha(ok, 0.2), ok3) +}) diff --git a/tests/testthat/test-deprecated.R b/tests/testthat/test-deprecated.R new file mode 100644 index 00000000..acfe8642 --- /dev/null +++ b/tests/testthat/test-deprecated.R @@ -0,0 +1,19 @@ +test_that("bde_vivid_pal", { + expect_snapshot(vpal <- bde_vivid_pal()(3)) + + + expect_identical( + bde_palettes(n = 3, "bde_vivid_pal"), + vpal + ) +}) + +test_that("bde_rose_pal", { + expect_snapshot(vpal <- bde_rose_pal()(4)) + + + expect_identical( + bde_palettes(n = 4, "bde_rose_pal"), + vpal + ) +}) diff --git a/tests/testthat/test-scales.R b/tests/testthat/test-scales.R new file mode 100644 index 00000000..8265be7f --- /dev/null +++ b/tests/testthat/test-scales.R @@ -0,0 +1,88 @@ +test_that("Discrete scale", { + d <- data.frame(x = 1:5, y = 1:5, z = 21:25, l = letters[1:5]) + + p <- ggplot2::ggplot(d) + + ggplot2::geom_point(ggplot2::aes(x, y, color = l)) + + init <- ggplot2::layer_data(p)$colour + p2 <- p + scale_color_bde_d() + + mod <- ggplot2::layer_data(p2)$colour + expect_true(!any(init %in% mod)) + + # Renamed + p3 <- p + scale_colour_bde_d() + mod3 <- ggplot2::layer_data(p3)$colour + expect_identical(mod, mod3) + + # Another pal + p4 <- p + scale_color_bde_d(palette = "bde_rose_pal") + mod4 <- ggplot2::layer_data(p4)$colour + + expect_false(any(mod == mod4)) + + # Another param + pf <- ggplot2::ggplot(d) + + ggplot2::geom_point(ggplot2::aes(x, y, fill = l), shape = 21) + + pfill <- pf + scale_fill_bde_d() + colfill <- ggplot2::layer_data(pfill)$fill + + expect_identical(mod, colfill) + + pfill2 <- pf + scale_fill_bde_d(palette = "bde_rose_pal") + colfill2 <- ggplot2::layer_data(pfill2)$fill + + expect_identical(mod4, colfill2) +}) + + +test_that("Continous scale", { + skip("Not ready yet") + d <- data.frame(x = 1:5, y = 1:5, z = 21:25, l = letters[1:5]) + + p <- ggplot2::ggplot(d) + + ggplot2::geom_point(ggplot2::aes(x, y, colour = z)) + + init <- ggplot2::layer_data(p)$colour + p2 <- p + scale_colour_terrain_c() + + mod <- ggplot2::layer_data(p2)$colour + expect_true(!any(init %in% mod)) + + # Renamed + p3 <- p + scale_color_terrain_c() + mod3 <- ggplot2::layer_data(p3)$colour + expect_identical(mod, mod3) + + + # Alpha + expect_snapshot(p + scale_colour_terrain_c(alpha = -1), + error = TRUE + ) + + p3 <- p + scale_colour_terrain_c(alpha = 0.9) + + mod_alpha <- ggplot2::layer_data(p3)$colour + + expect_true(all(adjustcolor(mod, alpha.f = 0.9) == mod_alpha)) + + # Reverse also with alpha + expect_snapshot(p + scale_colour_terrain_c(direction = 0.5), + error = TRUE + ) + + + + p4 <- p + scale_colour_terrain_c( + direction = -1, + alpha = 0.7 + ) + + mod_alpha_rev <- ggplot2::layer_data(p4)$colour + + + expect_true( + all(rev(adjustcolor(mod, alpha.f = 0.7)) == mod_alpha_rev) + ) +})