Closed mtennekes closed 8 months ago
@kwstat this would be a simple but super useful feature! I use pals for quite a few packages and it would be great to have this information.
@mtennekes in the meantime I wrote a small function to try and get some of this information from an internal object within pals
:
pals_info <- function(){
maxcolors <- NULL;
syspals <- utils::getFromNamespace("syspals", "pals")
pdt <- lapply(syspals, function(x){
if(is.list(x)){
length(x[[length(x)]])
} else {
Inf
}
}) |>
unlist()|>
data.table::as.data.table(keep.rownames=TRUE) |>
`colnames<-`(c("palette","maxcolors"))
pdt[,is_finite:=is.finite(maxcolors)]
data.table::setorderv(pdt,"maxcolors",na.last=TRUE)
return(pdt)
}
pdt <- pals_info()
This is_finite
column is least helpful when determining which palettes wouldn't be suitable when you need some unknown large number of colors.
@kwstat let me know if a version of this would be helpful and I can make a PR.
Actually, that function I provided wasn't very accurate. This one should work much better as I'm inferring the max number of colors from the default arguments in each function (after checking that it really is an exported function):
pals_info <- function(){
maxcolors <- NULL;
ns <- getNamespaceExports("pals")
syspals <- utils::getFromNamespace("syspals", "pals")
pdt <- sapply(names(syspals)[names(syspals) %in% ns],
function(p){
f <- formals(utils::getFromNamespace(p,"pals"))
if(!"n" %in% names(f)) return(NA)
if(rlang::is_missing(f$n)) Inf else eval(f$n)
}) |>
data.table::as.data.table(keep.rownames=TRUE) |>
`colnames<-`(c("palette","maxcolors"))
pdt[,is_finite:=is.finite(maxcolors)]
data.table::setorderv(pdt,"maxcolors",na.last=TRUE)
return(pdt)
}
Is it possible to remove the use of data.table and rlang? Those are currently not included in DEPENDS for the package. I suggest naming the function pals.maxcolors or something similar. This makes it more informative than "info" and using "." makes it consistent with other functions in the package. (I probably should have used "_" instead of "." but that decision was made a LONG time ago).
Is it possible to remove the use of data.table and rlang? Those are currently not included in DEPENDS for the package. I suggest naming the function pals.maxcolors or something similar. This makes it more informative than "info" and using "." makes it consistent with other functions in the package. (I probably should have used "_" instead of "." but that decision was made a LONG time ago).
Sure! that should be easy enough. I can make a PR soon.
Just made the PR here @mtennekes @kwstat :
Closed via #11
Do you have meta data of the palettes? Specifically:
So I'm looking for something similar as:
Created on 2021-06-10 by the reprex package (v2.0.0)
We can classify 'rainbow' palettes as sequential. The bivariate palettes (great that you have them!) are a category on their own.
(As you may know I'll use
pals
fortmap
: see https://github.com/mtennekes/tmap/issues/566)