Skip to content

Commit

Permalink
Add icsColor()
Browse files Browse the repository at this point in the history
* Add icsColor() a convenience fct
* Documented icsColor and ICS_Colors
* Add some basic tests for icsColor()
  • Loading branch information
abuseki committed Nov 25, 2023
1 parent 877b02b commit 9115cb0
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(icsColor)
export(m)
export(minSearch)
export(minsForChemistry)
Expand Down
58 changes: 47 additions & 11 deletions R/ICS_Colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,60 @@
#' @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}
#'
#' \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])
}
2 changes: 2 additions & 0 deletions R/georefdatar-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
#' @name georefdatar_package
#' @rdname georefdatar_package
NULL

globalVariables(c("ICS_Colors"))
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ PGE
IPGE
PPGE
MREE
eontheme
eratheme
22 changes: 10 additions & 12 deletions man/ICS_Colors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions man/icsColor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/test-ICS_Colors.R
Original file line number Diff line number Diff line change
@@ -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)
)

})

0 comments on commit 9115cb0

Please sign in to comment.