Permalink
Browse files

Add gg_dep function for gradual deprecation

  • Loading branch information...
wch committed Oct 23, 2012
1 parent 47c19c5 commit 64d0f5ab17bcaea63fa68bdfbd96ac0e0cdcec06
Showing with 69 additions and 37 deletions.
  1. +1 −1 R/coord-cartesian-.r
  2. +1 −1 R/coord-fixed.r
  3. +1 −1 R/layer.r
  4. +1 −2 R/matrix.r
  5. +7 −7 R/scale-.r
  6. +4 −4 R/scale-area.r
  7. +7 −6 R/stat-bin.r
  8. +1 −1 R/stat-ydensity.r
  9. +6 −6 R/templates.r
  10. +5 −5 R/theme-elements.r
  11. +4 −3 R/theme.r
  12. +31 −0 R/utilities.r
View
@@ -39,7 +39,7 @@
#' d + coord_cartesian(xlim = c(0, 2))
coord_cartesian <- function(xlim = NULL, ylim = NULL, wise = NULL) {
if (!is.null(wise))
- warning("Deprecated: wise argument to coord_cartesian is ignored", call. = FALSE)
+ gg_dep("0.9.0", "wise argument to coord_cartesian is ignored")
coord(limits = list(x = xlim, y = ylim), subclass = "cartesian")
}
View
@@ -23,7 +23,7 @@
#' # Resize the plot to see that the specified aspect ratio is maintained
coord_fixed <- function(ratio = 1, xlim = NULL, ylim = NULL, wise = NULL) {
if (!is.null(wise))
- warning("Deprecated: wise argument to coord_cartesian is ignored", call. = FALSE)
+ gg_dep("0.9.0", "wise argument to coord_cartesian is ignored")
coord(limits = list(x = xlim, y = ylim), ratio = ratio,
subclass = c("fixed", "cartesian"))
View
@@ -27,7 +27,7 @@ Layer <- proto(expr = {
# now, as for the guide, we can choose only if the layer is included or not in the guide: guide = TRUE or guide = FALSE
# in future, it may be better if we can choose which aes of this layer is included in the guide, e.g.: guide = c(colour = TRUE, size = FALSE)
if (!is.na(legend)) {
- warning("\"legend\" argument in geom_XXX and stat_XXX is deprecated. Use show_guide = TRUE or show_guide = FALSE for display or suppress the guide display.")
+ gg_dep("0.8.9", "\"legend\" argument in geom_XXX and stat_XXX is deprecated. Use show_guide = TRUE or show_guide = FALSE for display or suppress the guide display.")
show_guide = legend
}
View
@@ -9,8 +9,7 @@
#' plotmatrix(mtcars[, 1:3])
#' plotmatrix(mtcars[, 1:3]) + geom_smooth(method="lm")
plotmatrix <- function(data, mapping=aes(), colour="black") {
- # This function is now deprecated
- warning("This function is deprecated. For a replacement, see the ggpairs function in the GGally package.")
+ gg_dep("0.9.2", "This function is deprecated. For a replacement, see the ggpairs function in the GGally package.")
# data <- rescaler(data, "range")
grid <- expand.grid(x=1:ncol(data), y=1:ncol(data))
View
@@ -38,7 +38,7 @@ NULL
continuous_scale <- function(aesthetics, scale_name, palette, name = NULL, breaks = waiver(), minor_breaks = waiver(), labels = waiver(), legend = NULL, limits = NULL, rescaler = rescale, oob = censor, expand = waiver(), na.value = NA_real_, trans = "identity", guide="legend") {
if (!is.null(legend)) {
- warning("\"legend\" argument in scale_XXX is deprecated. Use guide=\"none\" for suppress the guide display.")
+ gg_dep("0.8.9", "\"legend\" argument in scale_XXX is deprecated. Use guide=\"none\" for suppress the guide display.")
if (legend == FALSE) guide = "none"
else if (legend == TRUE) guide = "legend"
}
@@ -125,7 +125,7 @@ continuous_scale <- function(aesthetics, scale_name, palette, name = NULL, break
discrete_scale <- function(aesthetics, scale_name, palette, name = NULL, breaks = waiver(), labels = waiver(), legend = NULL, limits = NULL, expand = waiver(), na.value = NA, drop = TRUE, guide="legend") {
if (!is.null(legend)) {
- warning("\"legend\" argument in scale_XXX is deprecated. Use guide=\"none\" for suppress the guide display.")
+ gg_dep("0.8.9", "\"legend\" argument in scale_XXX is deprecated. Use guide=\"none\" for suppress the guide display.")
if (legend == FALSE) guide = "none"
else if (legend == TRUE) guide = "legend"
}
@@ -336,7 +336,7 @@ 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("breaks = NA is deprecated. Please use breaks = NULL to remove breaks in the scale.")
+ gg_dep("0.8.9", "breaks = NA is deprecated. Please use breaks = NULL to remove breaks in the scale.")
return(NULL)
} else if (zero_range(as.numeric(limits))) {
breaks <- limits[1]
@@ -367,7 +367,7 @@ 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("breaks = NA is deprecated. Please use breaks = NULL to remove breaks in the scale.")
+ gg_dep("0.8.9", "breaks = NA is deprecated. Please use breaks = NULL to remove breaks in the scale.")
return(NULL)
} else if (is.waive(scale$breaks)) {
breaks <- limits
@@ -400,7 +400,7 @@ 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("minor_breaks = NA is deprecated. Please use minor_breaks = NULL to remove minor breaks in the scale.")
+ gg_dep("0.8.9", "minor_breaks = NA is deprecated. Please use minor_breaks = NULL to remove minor breaks in the scale.")
return(NULL)
} else if (is.waive(scale$minor_breaks)) {
if (is.null(b)) {
@@ -449,7 +449,7 @@ 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("labels = NA is deprecated. Please use labels = NULL to remove labels in the scale.")
+ gg_dep("0.8.9", "labels = NA is deprecated. Please use labels = NULL to remove labels in the scale.")
return(NULL)
} else if (is.waive(scale$labels)) {
labels <- scale$trans$format(breaks)
@@ -471,7 +471,7 @@ scale_labels.discrete <- 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("labels = NA is deprecated. Please use labels = NULL to remove labels in the scale.")
+ gg_dep("0.8.9", "labels = NA is deprecated. Please use labels = NULL to remove labels in the scale.")
return(NULL)
}else if (is.waive(scale$labels)) {
format(scale_breaks(scale), justify = "none", trim = TRUE)
View
@@ -10,9 +10,9 @@
#' @param range Range of output sizes. Should be greater than 0.
#' @export
scale_area <- function(..., range = c(1, 6)) {
- message("scale_area is deprecated and will be removed in a future version of ggplot2.\n",
- " Use scale_size_area instead. Note that the behavior of scale_size_area is\n",
- " slightly different: by default it makes the area proportional to the\n",
- " numeric value.")
+ gg_dep("0.9.2",
+ "scale_area is deprecated. Use scale_size_area instead.\n",
+ " Note that the behavior of scale_size_area is slightly different: \n",
+ " by default it makes the area proportional to the numeric value.\n")
continuous_scale("size", "area", area_pal(range), ...)
}
View
@@ -57,12 +57,13 @@ StatBin <- proto(Stat, {
calculate_groups <- function(., data, ...) {
if (!is.null(data$y) || !is.null(match.call()$y)) {
# Deprecate this behavior
- message("Mapping a variable to y and also using stat=\"bin\".\n",
- " With stat=\"bin\", it will attempt to set the y value to the count of cases in each group.\n",
- " This can result in unexpected behavior and will not be allowed in a future version of ggplot2.\n",
- " If you want y to represent counts of cases, use stat=\"bin\" and don't map a variable to y.\n",
- " If you want y to represent values in the data, use stat=\"identity\".\n",
- " See ?geom_bar for examples.")
+ gg_dep("0.9.2", paste(sep = "\n",
+ "Mapping a variable to y and also using stat=\"bin\".",
+ " With stat=\"bin\", it will attempt to set the y value to the count of cases in each group.",
+ " This can result in unexpected behavior and will not be allowed in a future version of ggplot2.",
+ " If you want y to represent counts of cases, use stat=\"bin\" and don't map a variable to y.",
+ " If you want y to represent values in the data, use stat=\"identity\".",
+ " See ?geom_bar for examples."))
}
.$informed <- FALSE
View
@@ -45,7 +45,7 @@ StatYdensity <- proto(Stat, {
# choose how violins are scaled relative to each other
scale <- match.arg(scale, c("area", "equal", "count", "width"))
if (scale == "equal") {
- .Deprecated("scale=\"area\"", old="scale=\"equal\"")
+ gg_dep("0.9.2", "scale=\"area\" is deprecated; in the future, use scale=\"equal\" instead.")
scale <- "area"
}
View
@@ -24,7 +24,7 @@
#' p + geom_line(aes(colour=mpg))
#' }
ggpcp <- function(data, vars=names(data), ...) {
- .Deprecated()
+ gg_dep("0.9.1", "ggpcp is deprecated.")

This comment has been minimized.

Show comment Hide comment
@yihui

yihui Nov 7, 2012

Contributor

Then what should be used instead for pcp? http://stackoverflow.com/q/13196883/559676 GGally? I did not see anything mentioned in the NEWS.

@yihui

yihui Nov 7, 2012

Contributor

Then what should be used instead for pcp? http://stackoverflow.com/q/13196883/559676 GGally? I did not see anything mentioned in the NEWS.

scaled <- as.data.frame(lapply(data[, vars], rescale01))
data <- cunion(scaled, data)
@@ -60,7 +60,7 @@ ggpcp <- function(data, vars=names(data), ...) {
#' ggfluctuation(table(warpbreaks$breaks, warpbreaks$tension))
#' }
ggfluctuation <- function(table, type="size", floor=0, ceiling=max(table$freq, na.rm=TRUE)) {
- .Deprecated()
+ gg_dep("0.9.1", "ggfluctuation is deprecated.")
if (is.table(table)) table <- as.data.frame(t(table))
oldnames <- names(table)
@@ -130,7 +130,7 @@ ggfluctuation <- function(table, type="size", floor=0, ceiling=max(table$freq, n
#' ggmissing(mmissing, avoid="dodge") + scale_y_sqrt()
#' }
ggmissing <- function(data, avoid="stack", order=TRUE, missing.only = TRUE) {
- .Deprecated()
+ gg_dep("0.9.1", "ggmissing is deprecated.")
missings <- mapply(function(var, name) cbind(as.data.frame(table(missing=factor(is.na(var), levels=c(TRUE, FALSE), labels=c("yes", "no")))), variable=name),
data, names(data), SIMPLIFY=FALSE
)
@@ -162,7 +162,7 @@ ggmissing <- function(data, avoid="stack", order=TRUE, missing.only = TRUE) {
#' ggstructure(mtcars)
#' }
ggstructure <- function(data) {
- .Deprecated()
+ gg_dep("0.9.1", "ggstructure is deprecated.")
ggpcp(data) +
aes_string(y="ROWID", fill="value", x="variable") +
geom_tile() +
@@ -175,7 +175,7 @@ ggstructure <- function(data) {
#' @param data data set to plot
#' @export
ggorder <- function(data) {
- .Deprecated()
+ gg_dep("0.9.1", "ggorder is deprecated.")
ggpcp(data) +
aes_string(x="ROWID", group="variable", y="value") +
facet_grid(. ~ variable) +
@@ -185,7 +185,7 @@ ggorder <- function(data) {
# Distribution plot.
ggdist <- function(data, vars=names(data), facets = . ~ .) {
- .Deprecated()
+ gg_dep("0.9.1", "ggdist is deprecated.")
cat <- sapply(data[vars], is.factor)
facets <- deparse(substitute(facets))
View
@@ -104,35 +104,35 @@ is.rel <- function(x) inherits(x, "rel")
#'
#' @export
theme_blank <- function(...) {
- .Deprecated(new = "element_blank")
+ gg_dep("0.9.1", "'theme_blank' is deprecated. Use 'element_blank' instead.")
element_blank(...)
}
#' @rdname theme_blank
#' @export
theme_rect <- function(...) {
- .Deprecated(new = "element_rect")
+ gg_dep("0.9.1", "theme_rect is deprecated. Use 'element_rect' instead.")
element_rect(...)
}
#' @rdname theme_blank
#' @export
theme_line <- function(...) {
- .Deprecated(new = "element_line")
+ gg_dep("0.9.1", "theme_line is deprecated. Use 'element_line' instead.")
element_line(...)
}
#' @rdname theme_blank
#' @export
theme_segment <- function(...) {
- .Deprecated(new = "element_line")
+ gg_dep("0.9.1", "theme_segment is deprecated. Use 'element_segment' instead.")
element_line(...)
}
#' @rdname theme_blank
#' @export
theme_text <- function(...) {
- .Deprecated(new = "element_text")
+ gg_dep("0.9.1", "theme_text is deprecated. Use 'element_text' instead.")
element_text(...)
}
View
@@ -320,14 +320,15 @@ theme <- function(..., complete = FALSE) {
#'
#' @export
opts <- function(...) {
- .Deprecated(new = "theme")
+ gg_dep("0.9.1", "'opts' is deprecated. Use 'theme' instead.")
# Add check for deprecated elements
extra <- NULL
elements <- list(...)
if (!is.null(elements[["title"]])) {
# This is kind of a hack, but fortunately it will be removed in future versions
- warning('Setting the plot title with opts(title="...") is deprecated.',
+ gg_dep("0.9.1",
+ 'Setting the plot title with opts(title="...") is deprecated.',
' Use labs(title="...") or ggtitle("...") instead.')
title <- elements$title
@@ -511,7 +512,7 @@ update_theme <- function(oldtheme, newtheme) {
##' update_element("axis.text", colour = 20)
##' }
update_element <- function(name, ...) {
- .Deprecated(new = "+.gg")
+ gg_dep("0.9.1", "update_element is deprecated. Use '+.gg' instead.")
if (is.character(name)) {
ele <- theme_get()[[name]]
if (is.null(ele)) {
View
@@ -195,3 +195,34 @@ if (packageVersion("plyr") <= package_version("1.7.1")) {
} else {
rename <- plyr::rename
}
+
+
+# Give a deprecation error, warning, or messsage, depending on version number.
+#
+# @param version The _last_ version of ggplot2 where this function was good
+# (in other words, the last version where it was not deprecated).
+# @param message The message to print
+gg_dep <- function(version, msg) {
+ v <- as.package_version(version)
+ cv <- packageVersion("ggplot2")
+
+ # Version number is major.minor.subminor, like 0.9.2
+ # If current major number is greater than last-good major number, or if
+ # current minor number is more than 1 greater than last-good minor number,
+ # give error.
+ if (cv[[1,1]] > v[[1,1]] || cv[[1,2]] > v[[1,2]] + 1) {
+ error(msg, " (Defunct; last used in version ", version, ")",
+ call. = FALSE)
+
+ # If minor number differs by one, give warning
+ } else if (cv[[1,2]] > v[[1,2]]) {
+ warning(msg, " (Deprecated; last used in version ", version, ")",
+ call. = FALSE)
+
+ # If only subminor number is greater, give message
+ } else if (cv[[1,3]] > v[[1,3]]) {
+ message(msg, " (Deprecated; last used in version ", version, ")")
+ }
+
+ invisible()
+}

0 comments on commit 64d0f5a

Please sign in to comment.