-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from bschilder/main
New function: `pals.maxcolors`
- Loading branch information
Showing
7 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Package: pals | ||
Version: 1.8 | ||
Version: 1.9 | ||
Authors@R: person("Kevin","Wright", email="[email protected]", comment=c(ORCID = "0000-0002-0617-8673"), role=c("aut","cre","cph")) | ||
Title: Color Palettes, Colormaps, and Tools to Evaluate Them | ||
Description: A comprehensive collection of color palettes, colormaps, and tools to evaluate them. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' Pals max colors | ||
#' | ||
#' This function returns a data frame with the maximum number of colors for | ||
#' each palette currently available within the \pkg{pals} package. | ||
#' @returns A data frame with the maximum number of colors for each palette. | ||
#' @author R code by Brian M Schilder. | ||
#' @export | ||
#' @importFrom utils getFromNamespace | ||
#' @examples | ||
#' dat <- pals.maxcolors() | ||
pals.maxcolors <- function(){ | ||
## Copied function from rlang::is_missing | ||
is_missing <- function (x) { | ||
missing(x) || identical(x, quote(expr = )) | ||
} | ||
## Get all exported pals functions | ||
ns <- getNamespaceExports("pals") | ||
syspals <- utils::getFromNamespace("syspals", "pals") | ||
## Filter out the functions that don't actually exist | ||
syspals <- syspals[names(syspals) %in% ns] | ||
dat <- lapply(names(syspals), | ||
function(p){ | ||
f <- formals(utils::getFromNamespace(p,"pals")) | ||
if(!"n" %in% names(f)) return(NA) | ||
maxcolors <- if(is_missing(f$n)) Inf else eval(f$n) | ||
return( | ||
data.frame(palette=p, | ||
maxcolors=maxcolors, | ||
is_finite=is.finite(maxcolors), | ||
stringsAsFactors=FALSE | ||
) | ||
) | ||
}) |> Reduce(f=rbind) | ||
## Sort by maxcolors | ||
dat <- dat[order(dat$maxcolors),] | ||
return(dat) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
test_that("pals.maxcolors works", { | ||
dat <- pals.maxcolors() | ||
testthat::expect_true(all( | ||
c("palette","maxcolors","is_finite") %in% names(dat) | ||
)) | ||
testthat::expect_gte(nrow(dat), 127) | ||
}) |