From 3b42b984c6265f1ec96f8c684cb31aa1d5a27440 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Sep 2024 20:14:45 +0200 Subject: [PATCH] add `key_none()` --- NAMESPACE | 1 + R/aaa.R | 3 +++ R/key-.R | 13 +++++++++++++ man/key_standard.Rd | 7 +++++++ 4 files changed, 24 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 7e9015c..4b41335 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -51,6 +51,7 @@ export(key_log) export(key_manual) export(key_map) export(key_minor) +export(key_none) export(key_range_auto) export(key_range_manual) export(key_range_map) diff --git a/R/aaa.R b/R/aaa.R index 565041e..91eb459 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -25,6 +25,9 @@ standard_extract_key <- function(scale, aesthetic, key, ...) { if (is.function(key)) { key <- key(scale, aesthetic) } + if (is_empty(key)) { + return(key) + } if ("aesthetic" %in% names(key)) { key$aesthetic <- scale_transform(key$aesthetic, scale, map = TRUE, "aesthetic") diff --git a/R/key-.R b/R/key-.R index 7e1f187..f278377 100644 --- a/R/key-.R +++ b/R/key-.R @@ -15,6 +15,7 @@ #' break positions for minor tick marks. #' * `key_log()` is a function factory whose functions place ticks at intervals #' in log10 space. +#' * `key_none()` makes an empty key with no entries. #' #' @param aesthetic,value A vector of values for the guide to represent #' equivalent to the `breaks` argument in scales. The `aesthetic` will be @@ -75,6 +76,9 @@ #' #' # Values from a `` #' key_map(ToothGrowth, aesthetic = unique(supp)) +#' +#' # Empty key +#' key_none() NULL #' @rdname key_standard @@ -171,6 +175,15 @@ key_log <- function( } } +#' @rdname key_standard +#' @export +key_none <- function() { + new_data_frame( + list(aesthetic = logical(), .value = logical(), .label = character()), + n = 0L, class = c("key_standard", "key_guide") + ) +} + # Helpers ----------------------------------------------------------------- validate_key_types <- function(key, call = caller_env()) { diff --git a/man/key_standard.Rd b/man/key_standard.Rd index 83ade01..d78aa16 100644 --- a/man/key_standard.Rd +++ b/man/key_standard.Rd @@ -7,6 +7,7 @@ \alias{key_map} \alias{key_minor} \alias{key_log} +\alias{key_none} \title{Standard keys} \usage{ key_auto(...) @@ -30,6 +31,8 @@ key_log( labeller = NULL, ... ) + +key_none() } \arguments{ \item{...}{\code{\link[rlang:topic-data-mask]{}} A set of mappings @@ -91,6 +94,7 @@ key from major breaks in a scale. break positions for minor tick marks. \item \code{key_log()} is a function factory whose functions place ticks at intervals in log10 space. +\item \code{key_none()} makes an empty key with no entries. } } \examples{ @@ -113,6 +117,9 @@ key_manual( # Values from a `` key_map(ToothGrowth, aesthetic = unique(supp)) + +# Empty key +key_none() } \seealso{ Other keys: