From 3686d497216f12dfe67fee2fa7154fc84e01d33e Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Tue, 31 Oct 2023 15:50:17 -0400 Subject: [PATCH 1/2] Remove usage of scales::_format functions. Use scales::label_*() instead. --- R/annotation-logticks.R | 4 ++-- R/axis-secondary.R | 4 ++-- R/scale-continuous.R | 6 +++--- R/scale-date.R | 4 ++-- man/annotation_logticks.Rd | 4 ++-- man/scale_continuous.Rd | 6 +++--- man/sec_axis.Rd | 4 ++-- tests/testthat/test-guides.R | 2 +- tests/testthat/test-scale_date.R | 8 ++++---- tests/testthat/test-scales-breaks-labels.R | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/R/annotation-logticks.R b/R/annotation-logticks.R index 3432cac3b5..1e7f60be65 100644 --- a/R/annotation-logticks.R +++ b/R/annotation-logticks.R @@ -61,8 +61,8 @@ #' # plotting it. Also hide the minor grid lines. #' b <- ggplot(msleep, aes(log10(bodywt), log10(brainwt))) + #' geom_point(na.rm = TRUE) + -#' scale_x_continuous(name = "body", labels = scales::math_format(10^.x)) + -#' scale_y_continuous(name = "brain", labels = scales::math_format(10^.x)) + +#' scale_x_continuous(name = "body", labels = scales::label_math(10^.x)) + +#' scale_y_continuous(name = "brain", labels = scales::label_math(10^.x)) + #' theme_bw() + theme(panel.grid.minor = element_blank()) #' #' b + annotation_logticks() diff --git a/R/axis-secondary.R b/R/axis-secondary.R index d0aac70e72..f08b3e420b 100644 --- a/R/axis-secondary.R +++ b/R/axis-secondary.R @@ -76,7 +76,7 @@ #' date_breaks = "6 hour", #' sec.axis = dup_axis( #' name = "Time of Day", -#' labels = scales::time_format("%I %p") +#' labels = scales::label_time("%I %p") #' ) #' ) #' @@ -89,7 +89,7 @@ #' sec.axis = sec_axis( #' ~ . + 8 * 3600, #' name = "GMT+8", -#' labels = scales::time_format("%b %d %I %p") +#' labels = scales::label_time("%b %d %I %p") #' ) #' ) #' diff --git a/R/scale-continuous.R b/R/scale-continuous.R index 9f0710b9d6..265364e778 100644 --- a/R/scale-continuous.R +++ b/R/scale-continuous.R @@ -53,9 +53,9 @@ #' y = seq(0, 1, length.out = 10) #' ) #' p2 <- ggplot(df, aes(x, y)) + geom_point() -#' p2 + scale_y_continuous(labels = scales::percent) -#' p2 + scale_y_continuous(labels = scales::dollar) -#' p2 + scale_x_continuous(labels = scales::comma) +#' p2 + scale_y_continuous(labels = scales::label_percent()) +#' p2 + scale_y_continuous(labels = scales::label_dollar()) +#' p2 + scale_x_continuous(labels = scales::label_comma()) #' #' # You can also override the default linear mapping by using a #' # transformation. There are three shortcuts: diff --git a/R/scale-date.R b/R/scale-date.R index 8c20532599..3824d232a1 100644 --- a/R/scale-date.R +++ b/R/scale-date.R @@ -308,8 +308,8 @@ datetime_scale <- function(aesthetics, trans, palette, } if (!is.waive(date_labels)) { labels <- function(self, x) { - tz <- if (is.null(self$timezone)) "UTC" else self$timezone - date_format(date_labels, tz)(x) + tz <- self$timezone %||% "UTC" + label_date(date_labels, tz)(x) } } diff --git a/man/annotation_logticks.Rd b/man/annotation_logticks.Rd index 088daf1fe1..92a587e708 100644 --- a/man/annotation_logticks.Rd +++ b/man/annotation_logticks.Rd @@ -92,8 +92,8 @@ a + annotation_logticks(sides = "trbl") + theme(panel.grid.minor = element_blank # plotting it. Also hide the minor grid lines. b <- ggplot(msleep, aes(log10(bodywt), log10(brainwt))) + geom_point(na.rm = TRUE) + - scale_x_continuous(name = "body", labels = scales::math_format(10^.x)) + - scale_y_continuous(name = "brain", labels = scales::math_format(10^.x)) + + scale_x_continuous(name = "body", labels = scales::label_math(10^.x)) + + scale_y_continuous(name = "brain", labels = scales::label_math(10^.x)) + theme_bw() + theme(panel.grid.minor = element_blank()) b + annotation_logticks() diff --git a/man/scale_continuous.Rd b/man/scale_continuous.Rd index f145e8c18a..1d376ef051 100644 --- a/man/scale_continuous.Rd +++ b/man/scale_continuous.Rd @@ -204,9 +204,9 @@ df <- data.frame( y = seq(0, 1, length.out = 10) ) p2 <- ggplot(df, aes(x, y)) + geom_point() -p2 + scale_y_continuous(labels = scales::percent) -p2 + scale_y_continuous(labels = scales::dollar) -p2 + scale_x_continuous(labels = scales::comma) +p2 + scale_y_continuous(labels = scales::label_percent()) +p2 + scale_y_continuous(labels = scales::label_dollar()) +p2 + scale_x_continuous(labels = scales::label_comma()) # You can also override the default linear mapping by using a # transformation. There are three shortcuts: diff --git a/man/sec_axis.Rd b/man/sec_axis.Rd index 0e7316aa5a..df69ba8e65 100644 --- a/man/sec_axis.Rd +++ b/man/sec_axis.Rd @@ -106,7 +106,7 @@ ggplot(df, aes(x = dx, y = price)) + date_breaks = "6 hour", sec.axis = dup_axis( name = "Time of Day", - labels = scales::time_format("\%I \%p") + labels = scales::label_time("\%I \%p") ) ) @@ -119,7 +119,7 @@ ggplot(df, aes(x = dx, y = price)) + sec.axis = sec_axis( ~ . + 8 * 3600, name = "GMT+8", - labels = scales::time_format("\%b \%d \%I \%p") + labels = scales::label_time("\%b \%d \%I \%p") ) ) diff --git a/tests/testthat/test-guides.R b/tests/testthat/test-guides.R index b00fe359c6..2ea4d3a696 100644 --- a/tests/testthat/test-guides.R +++ b/tests/testthat/test-guides.R @@ -500,7 +500,7 @@ test_that("guide_axis() draws minor ticks correctly", { axis.minor.ticks.length.x.top = unit(-0.5, "cm"), axis.minor.ticks.length.x.bottom = unit(0.75, "cm"), axis.minor.ticks.length.y.right = unit(5, "cm")) + - scale_x_continuous(labels = math_format()) + + scale_x_continuous(labels = label_math()) + guides( # Test for styling and style inheritance x = guide_axis(minor.ticks = TRUE), diff --git a/tests/testthat/test-scale_date.R b/tests/testthat/test-scale_date.R index 6e65f26f33..f12a35716c 100644 --- a/tests/testthat/test-scale_date.R +++ b/tests/testthat/test-scale_date.R @@ -22,11 +22,11 @@ test_that("date scale draws correctly", { expect_doppelganger("scale_x_date(breaks = \"3 weeks\")", dt + scale_x_date(date_breaks = "3 weeks") ) - expect_doppelganger("scale_x_date(labels = date_format(\"%m/%d\"))", - dt + scale_x_date(labels = date_format("%m/%d")) + expect_doppelganger("scale_x_date(labels = label_date(\"%m/%d\"))", + dt + scale_x_date(labels = label_date("%m/%d")) ) - expect_doppelganger("scale_x_date(labels = date_format(\"%W\"), \"week\")", - dt + scale_x_date(labels = date_format("%W"), "week") + expect_doppelganger("scale_x_date(labels = label_date(\"%W\"), \"week\")", + dt + scale_x_date(labels = label_date("%W"), "week") ) dt <- ggplot(df, aes(price, dx)) + geom_line() diff --git a/tests/testthat/test-scales-breaks-labels.R b/tests/testthat/test-scales-breaks-labels.R index 70936e3439..1516519512 100644 --- a/tests/testthat/test-scales-breaks-labels.R +++ b/tests/testthat/test-scales-breaks-labels.R @@ -321,7 +321,7 @@ test_that("minor breaks draw correctly", { ggplot(df, aes(x_date, y)) + geom_blank() + scale_x_date( - labels = scales::date_format("%m/%d"), + labels = scales::label_date("%m/%d"), breaks = scales::date_breaks("month"), minor_breaks = scales::date_breaks("week") ) + From ad853616027793df3eafe4383ae9dc249d82a782 Mon Sep 17 00:00:00 2001 From: Olivier Roy Date: Tue, 31 Oct 2023 15:52:20 -0400 Subject: [PATCH 2/2] Add periods at the end of the check_installed() messages. https://style.tidyverse.org/error-messages.html --- R/coord-map.R | 2 +- R/fortify-map.R | 2 +- R/fortify.R | 4 ++-- R/stat-binhex.R | 2 +- R/stat-quantilemethods.R | 2 +- R/stat-summary-hex.R | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/coord-map.R b/R/coord-map.R index 0b0744c1b0..ee0f6ad139 100644 --- a/R/coord-map.R +++ b/R/coord-map.R @@ -334,7 +334,7 @@ CoordMap <- ggproto("CoordMap", Coord, mproject <- function(coord, x, y, orientation) { - check_installed("mapproj", reason = "for `coord_map()`") + check_installed("mapproj", reason = "for `coord_map()`.") suppressWarnings(mapproj::mapproject(x, y, projection = coord$projection, parameters = coord$params, diff --git a/R/fortify-map.R b/R/fortify-map.R index dbf48ad334..d0dc76b716 100644 --- a/R/fortify-map.R +++ b/R/fortify-map.R @@ -78,7 +78,7 @@ fortify.map <- function(model, data, ...) { #' coord_map("albers", lat0 = 45.5, lat1 = 29.5) #' } map_data <- function(map, region = ".", exact = FALSE, ...) { - check_installed("maps", reason = "for `map_data()`") + check_installed("maps", reason = "for `map_data()`.") map_obj <- maps::map(map, region, exact = exact, plot = FALSE, fill = TRUE, ...) fortify(map_obj) } diff --git a/R/fortify.R b/R/fortify.R index dab0982b63..292928bba5 100644 --- a/R/fortify.R +++ b/R/fortify.R @@ -17,7 +17,7 @@ fortify.data.frame <- function(model, data, ...) model fortify.tbl_df <- function(model, data, ...) model #' @export fortify.tbl <- function(model, data, ...) { - check_installed("dplyr", reason = "to work with `tbl` objects") + check_installed("dplyr", reason = "to work with `tbl` objects.") dplyr::collect(model) } #' @export @@ -29,7 +29,7 @@ fortify.function <- function(model, data, ...) model fortify.formula <- function(model, data, ...) as_function(model) #' @export fortify.grouped_df <- function(model, data, ...) { - check_installed("dplyr", reason = "to work with `grouped_df` objects") + check_installed("dplyr", reason = "to work with `grouped_df` objects.") model$.group <- dplyr::group_indices(model) model } diff --git a/R/stat-binhex.R b/R/stat-binhex.R index 3e3f3d5911..0b5d3991c6 100644 --- a/R/stat-binhex.R +++ b/R/stat-binhex.R @@ -48,7 +48,7 @@ StatBinhex <- ggproto("StatBinhex", Stat, compute_group = function(data, scales, binwidth = NULL, bins = 30, na.rm = FALSE) { - check_installed("hexbin", reason = "for `stat_bin_hex()`") + check_installed("hexbin", reason = "for `stat_bin_hex()`.") binwidth <- binwidth %||% hex_binwidth(bins, scales) wt <- data$weight %||% rep(1L, nrow(data)) diff --git a/R/stat-quantilemethods.R b/R/stat-quantilemethods.R index f22b4ec687..9afb7e0b92 100644 --- a/R/stat-quantilemethods.R +++ b/R/stat-quantilemethods.R @@ -49,7 +49,7 @@ StatQuantile <- ggproto("StatQuantile", Stat, compute_group = function(data, scales, quantiles = c(0.25, 0.5, 0.75), formula = NULL, xseq = NULL, method = "rq", method.args = list(), lambda = 1, na.rm = FALSE) { - check_installed("quantreg", reason = "for `stat_quantile()`") + check_installed("quantreg", reason = "for `stat_quantile()`.") if (is.null(formula)) { if (method == "rqss") { diff --git a/R/stat-summary-hex.R b/R/stat-summary-hex.R index de435275c2..959630b4ac 100644 --- a/R/stat-summary-hex.R +++ b/R/stat-summary-hex.R @@ -45,7 +45,7 @@ StatSummaryHex <- ggproto("StatSummaryHex", Stat, compute_group = function(data, scales, binwidth = NULL, bins = 30, drop = TRUE, fun = "mean", fun.args = list()) { - check_installed("hexbin", reason = "for `stat_summary_hex()`") + check_installed("hexbin", reason = "for `stat_summary_hex()`.") binwidth <- binwidth %||% hex_binwidth(bins, scales) fun <- as_function(fun)