From 9115cb0bf7c5fb6a9c7e7739ebe8597b940cff1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerald=20Schuberth-Hlava=C4=8D?= Date: Sat, 25 Nov 2023 15:04:04 +0100 Subject: [PATCH] Add icsColor() * Add icsColor() a convenience fct * Documented icsColor and ICS_Colors * Add some basic tests for icsColor() --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/ICS_Colors.R | 58 ++++++++++++++++++++++++++------ R/georefdatar-package.R | 2 ++ README.Rmd | 2 +- README.md | 2 +- inst/WORDLIST | 2 ++ man/ICS_Colors.Rd | 22 ++++++------ man/icsColor.Rd | 31 +++++++++++++++++ tests/testthat/test-ICS_Colors.R | 22 ++++++++++++ 10 files changed, 118 insertions(+), 26 deletions(-) create mode 100644 man/icsColor.Rd create mode 100644 tests/testthat/test-ICS_Colors.R diff --git a/DESCRIPTION b/DESCRIPTION index fcc63ed..00133d0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: georefdatar Title: Geosciences reference data sets in R -Version: 0.4.2.9000 +Version: 0.4.3.9000 Authors@R: person("Gerald", "Schuberth-Hlavač", email= "abuseki@synapticgap.com", role = c("aut", "cre")) diff --git a/NAMESPACE b/NAMESPACE index caa00f5..19cdf2f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(icsColor) export(m) export(minSearch) export(minsForChemistry) diff --git a/R/ICS_Colors.R b/R/ICS_Colors.R index 3e3683c..0c9e900 100644 --- a/R/ICS_Colors.R +++ b/R/ICS_Colors.R @@ -12,18 +12,16 @@ #' @format #' A data frame with `r nrow(ICS_Colors)` rows and the following #' `r ncol(ICS_Colors)` columns:\cr -#' 1. `standard sorting order` ICS' ordering of this entry -#' 2. `Long List (isc:)` Entries name prefixed by `ics:` -#' 3. `Long List (formatted)` The (common) name of entry, e.g. 'Holocene' -#' 4. `Rank` Is the entry a System, Series, Stage, ... -#' 5. `Cyan` CMYK colors -#' 6. `Magenta` -#' 7. `Yellow` -#' 8. `Black` -#' 9. `Red` RGB colors -#' 10. `Green` -#' 11. `Blue` +#' \describe{ +#' \item{standard sorting order}{ICS' ordering of this entry} +#' \item{Long List (isc:)}{Entries name prefixed by `ics:`} +#' \item{Long List (formatted)}{The (common) name of entry, e.g. 'Holocene'} +#' \item{Rank}{Is the entry a System, Series, Stage, ...} +#' \item{Cyan, Magenta, Yellow, Black}{Color's values in the CMYK color model} +#' \item{Red, Green, Blue}{Color's values in the RGB color model} +#' } #' +#' @seealso [georefdatar::icsColor()] a convenience function to get a specific color. #' #' @references{ #' \insertRef{Cohen2013}{georefdatar} @@ -31,5 +29,43 @@ #' \insertRef{Vrielynck2022}{georefdatar} #' } #' +#' #' @importFrom Rdpack reprompt "ICS_Colors" + + + +#' Get ICS Color for a unit name found in the International Chronostratigraphic +#' Chart. +#' +#' Retrieve the color code for a given name of an eontheme, eratheme, system, +#' ... from the color codes of the International Chronostratigraphic Chart. +#' +#' @param name character. The name of a unit: eontheme to stage +#' @param colorModel character. The color model to get the color codes in -- +#' either 'RGB' (default) or 'CMYK'. +#' +#' @return list of the color code in the chosen color model +#' @export +#' +#' @seealso [georefdatar::ICS_Colors] for the full color code table +#' +#' @examples +#' # Color codes of the Permian in RGB +#' icsColor("Permian") +#' +#' +icsColor <- function(name, colorModel="RGB") { + cms <- c("RGB", "CMYK") + + stopifnot("colorModel must be 'RBG' or 'CMYK'."= colorModel %in% cms) + if ( (name %in% ICS_Colors$`Long List (formatted)`) == FALSE ) + stop(sprintf('"%s" is unknown.', name)) + + if(colorModel == 'RGB') + colorCols <- c('Red', 'Green', 'Blue') + else + colorCols <- c('Cyan', 'Magenta', 'Yellow', 'Black') + + as.list(ICS_Colors[ICS_Colors$`Long List (formatted)` == name, colorCols]) +} diff --git a/R/georefdatar-package.R b/R/georefdatar-package.R index e41935b..2b1d5b1 100644 --- a/R/georefdatar-package.R +++ b/R/georefdatar-package.R @@ -19,3 +19,5 @@ #' @name georefdatar_package #' @rdname georefdatar_package NULL + +globalVariables(c("ICS_Colors")) diff --git a/README.Rmd b/README.Rmd index 70499a9..9059df2 100644 --- a/README.Rmd +++ b/README.Rmd @@ -23,7 +23,7 @@ Up to now these are: * tables of decay constants and isotopic rations frequently used in geochronology * color codes of the [International Chronostratigraphic Chart](https://stratigraphy.org/chart) -* Sets of elements regullary use in geochemistry, e. g. REE, HREE, PGE, ... +* Sets of elements regularly used in geochemistry, e. g. REE, HREE, PGE, ... * some functions for basic queries of the periodic table of the elements and the list of minerals are also included. diff --git a/README.md b/README.md index c2dbc00..fc89cbc 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Up to now these are: geochronology - color codes of the [International Chronostratigraphic Chart](https://stratigraphy.org/chart) -- Sets of elements regullary use in geochemistry, e. g. REE, HREE, PGE, +- Sets of elements regularly used in geochemistry, e. g. REE, HREE, PGE, … - some functions for basic queries of the periodic table of the elements and the list of minerals are also included. diff --git a/inst/WORDLIST b/inst/WORDLIST index 2dbaef5..a8a89f3 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -56,3 +56,5 @@ PGE IPGE PPGE MREE +eontheme +eratheme diff --git a/man/ICS_Colors.Rd b/man/ICS_Colors.Rd index a5c8bc7..eb5e828 100644 --- a/man/ICS_Colors.Rd +++ b/man/ICS_Colors.Rd @@ -7,18 +7,13 @@ \format{ A data frame with 194 rows and the following 11 columns:\cr -\enumerate{ -\item \verb{standard sorting order} ICS' ordering of this entry -\item \verb{Long List (isc:)} Entries name prefixed by \verb{ics:} -\item \verb{Long List (formatted)} The (common) name of entry, e.g. 'Holocene' -\item \code{Rank} Is the entry a System, Series, Stage, ... -\item \code{Cyan} CMYK colors -\item \code{Magenta} -\item \code{Yellow} -\item \code{Black} -\item \code{Red} RGB colors -\item \code{Green} -\item \code{Blue} +\describe{ +\item{standard sorting order}{ICS' ordering of this entry} +\item{Long List (isc:)}{Entries name prefixed by \verb{ics:}} +\item{Long List (formatted)}{The (common) name of entry, e.g. 'Holocene'} +\item{Rank}{Is the entry a System, Series, Stage, ...} +\item{Cyan, Magenta, Yellow, Black}{Color's values in the CMYK color model} +\item{Red, Green, Blue}{Color's values in the RGB color model} } } \usage{ @@ -42,4 +37,7 @@ The coloring in this chart follows the \insertRef{Vrielynck2022}{georefdatar} } } +\seealso{ +\code{\link[=icsColor]{icsColor()}} a convenience function to get a specific color. +} \keyword{datasets} diff --git a/man/icsColor.Rd b/man/icsColor.Rd new file mode 100644 index 0000000..1fdd883 --- /dev/null +++ b/man/icsColor.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ICS_Colors.R +\name{icsColor} +\alias{icsColor} +\title{Get ICS Color for a unit name found in the International Chronostratigraphic +Chart.} +\usage{ +icsColor(name, colorModel = "RGB") +} +\arguments{ +\item{name}{character. The name of a unit: eontheme to stage} + +\item{colorModel}{character. The color model to get the color codes in -- +either 'RGB' (default) or 'CMYK'.} +} +\value{ +list of the color code in the chosen color model +} +\description{ +Retrieve the color code for a given name of an eontheme, eratheme, system, +... from the color codes of the International Chronostratigraphic Chart. +} +\examples{ +# Color codes of the Permian in RGB +icsColor("Permian") + + +} +\seealso{ +\link{ICS_Colors} for the full color code table +} diff --git a/tests/testthat/test-ICS_Colors.R b/tests/testthat/test-ICS_Colors.R new file mode 100644 index 0000000..9996232 --- /dev/null +++ b/tests/testthat/test-ICS_Colors.R @@ -0,0 +1,22 @@ +test_that("icsColors works", { + expect_error( + icsColor("XXXXXXian", "THIS NO COLORMODEL"), + "colorModel must be 'RBG' or 'CMYK'." + ) + + expect_error( + icsColor("XXXXXXian"), + '"XXXXXXian" is unknown.' + ) + + expect_equal( + icsColor('Greenlandian'), + list(Red=254, Green= 236, Blue=219) + ) + + expect_equal( + icsColor('Rhuddanian', colorModel= 'CMYK'), + list(Cyan= 35, Magenta= 0, Yellow=25, Black= 0) + ) + +})