From 53a562568acadfe7b7a132ac571f2050b1e0cd0e Mon Sep 17 00:00:00 2001 From: "Kohske Takahashi @ ayaka" Date: Fri, 10 Feb 2012 07:59:18 +0100 Subject: [PATCH] support NA for scale breaks/labels with warning message. --- R/scale-.r | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/R/scale-.r b/R/scale-.r index 59ddb1275a..5e708064df 100644 --- a/R/scale-.r +++ b/R/scale-.r @@ -262,6 +262,9 @@ scale_breaks.continuous <- function(scale, limits = scale_limits(scale)) { if (is.null(scale$breaks)) { return(NULL) + } else if (length(scale$breaks) == 1 && !is.function(scale$breaks) && is.na(scale$breaks)) { + warning("Use `breaks = NULL` instead of `breaks = NA` for suppressing breaks.") + return(NULL) } else if (zero_range(as.numeric(limits))) { breaks <- limits[1] } else if (is.waive(scale$breaks)) { @@ -286,6 +289,9 @@ scale_breaks.continuous <- function(scale, limits = scale_limits(scale)) { scale_breaks.discrete <- function(scale, limits = scale_limits(scale)) { if (is.null(scale$breaks)) { return(NULL) + } else if (length(scale$breaks) == 1 && !is.function(scale$breaks) && is.na(scale$breaks)) { + warning("Use `breaks = NULL` instead of `breaks = NA` for suppressing breaks.") + return(NULL) } else if (is.waive(scale$breaks)) { breaks <- limits } else if (is.function(scale$breaks)) { @@ -316,6 +322,9 @@ scale_breaks_minor.continuous <- function(scale, n = 2, b = scale_break_position if (is.null(scale$minor_breaks)) { return(NULL) + } else if (length(scale$minor_breaks) == 1 && !is.function(scale$minor_breaks) && is.na(scale$minor_breaks)) { + warning("Use `minor_breaks = NULL` instead of `minor_breaks = NA` for suppressing breaks.") + return(NULL) } else if (is.waive(scale$minor_breaks)) { b <- b[!is.na(b)] if (length(b) < 2) return() @@ -339,11 +348,14 @@ scale_breaks_minor.date <- function(scale, n = 2, b = scale_break_positions(scal limits <- scale$trans$inv(limits) if (zero_range(as.numeric(limits))) { - return() + return(NULL) } if (is.null(scale$minor_breaks)) { return(NULL) + } else if (length(scale$minor_breaks) == 1 && !is.function(scale$minor_breaks) && is.na(scale$minor_breaks)) { + warning("Use `minor_breaks = NULL` instead of `minor_breaks = NA` for suppressing breaks.") + return(NULL) } else if (is.waive(scale$minor_breaks)) { b <- b[!is.na(b)] if (length(b) < 2) return() @@ -385,6 +397,9 @@ scale_labels.continuous <- function(scale, breaks = scale_breaks(scale)) { if (is.null(scale$labels)) { return(NULL) + } else if (length(scale$labels) == 1 && !is.function(scale$labels) && is.na(scale$labels)) { + warning("Use `labels = NULL` instead of `labels = NA` for suppressing breaks.") + return(NULL) } else if (is.waive(scale$labels)) { labels <- scale$trans$format(breaks) } else if (is.function(scale$labels)) { @@ -404,7 +419,10 @@ scale_labels.discrete <- function(scale, breaks = scale_breaks(scale)) { if (is.null(scale$labels)) { return(NULL) - } else if (is.waive(scale$labels)) { + } else if (length(scale$labels) == 1 && !is.function(scale$labels) && is.na(scale$labels)) { + warning("Use `labels = NULL` instead of `labels = NA` for suppressing breaks.") + return(NULL) + }else if (is.waive(scale$labels)) { format(scale_breaks(scale), justify = "none", trim = TRUE) } else if (is.function(scale$labels)) { scale$labels(breaks)