From e8aca305c0153664136987f087154fbc20d836b9 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 16 Apr 2024 11:35:27 +0200 Subject: [PATCH] fixes for r cmd check --- R/pal-.R | 3 ++- R/pal-manual.R | 2 +- man/new_continuous_palette.Rd | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/R/pal-.R b/R/pal-.R index dd2bd50f..46e34573 100644 --- a/R/pal-.R +++ b/R/pal-.R @@ -18,6 +18,7 @@ #' that can be returned by the discrete palette. #' @param x An object to test or coerce. #' @param pal A palette to retrieve properties from. +#' @param ... Additional arguments. Currently not in use. #' #' @return #' For `new_continuous_palette()`, `new_discret_palette()`, `as_discrete_pal()` @@ -187,7 +188,7 @@ as_continuous_pal.pal_discrete <- function(x, ...) { type, color = , colour = colour_ramp(x(nlevels)), numeric = new_continuous_palette( - approxfun(seq(0, 1, length.out = nlevels), x(nlevels)), + stats::approxfun(seq(0, 1, length.out = nlevels), x(nlevels)), type = "numeric", na_safe = FALSE ), cli::cli_abort( diff --git a/R/pal-manual.R b/R/pal-manual.R index 6c3c6ca1..b8246272 100644 --- a/R/pal-manual.R +++ b/R/pal-manual.R @@ -35,5 +35,5 @@ guess_pal_type <- function(x) { is_color <- function(x) { # '#' followed by 3,4,6 or 8 hex digits grepl("^#(([[:xdigit:]]{2}){3,4}|([[:xdigit:]]){3,4})$", x) | - x %in% colours() + x %in% grDevices::colours() } diff --git a/man/new_continuous_palette.Rd b/man/new_continuous_palette.Rd index f9593940..49860805 100644 --- a/man/new_continuous_palette.Rd +++ b/man/new_continuous_palette.Rd @@ -58,6 +58,8 @@ that can be returned by the discrete palette.} \item{x}{An object to test or coerce.} \item{pal}{A palette to retrieve properties from.} + +\item{...}{Additional arguments. Currently not in use.} } \value{ For \code{new_continuous_palette()}, \code{new_discret_palette()}, \code{as_discrete_pal()} @@ -72,13 +74,35 @@ These constructor functions attach metadata to palette functions. This metadata can be used in testing or coercion. } \examples{ +# Creating a new discrete palette new_discrete_palette( fun = grDevices::terrain.colors, type = "colour", nlevels = 255 ) +# Creating a new continuous palette new_continuous_palette( fun = function(x) rescale(x, to = c(1, 0)), type = "numeric", na_safe = FALSE ) + +# Testing palette properties +is_continuous_pal(pal_seq_gradient()) +is_discrete_pal(pal_viridis()) +is_numeric_pal(pal_area()) +is_colour_pal(pal_manual(c("red", "green"))) +is_pal(transform_log10()) + +# Extracting properties +palette_nlevels(pal_viridis()) +palette_na_safe(colour_ramp(c("red", "green"), na.color = "grey50")) +palette_type(pal_shape()) + +# Switching discrete to continuous +pal <- as_continuous_pal(pal_viridis()) +show_col(pal(c(0, 0.1, 0.2, 0.4, 1))) + +# Switching continuous to discrete +pal <- as_discrete_pal(pal_div_gradient()) +show_col(pal(9)) }