Skip to content

Commit fc830ce

Browse files
authored
Use scales::label_* over scales::*format()` (#5504)
* Remove usage of scales::_format functions. Use scales::label_*() instead. * Add periods at the end of the check_installed() messages. https://style.tidyverse.org/error-messages.html
1 parent 916dc89 commit fc830ce

16 files changed

+29
-29
lines changed

R/annotation-logticks.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
#' # plotting it. Also hide the minor grid lines.
6262
#' b <- ggplot(msleep, aes(log10(bodywt), log10(brainwt))) +
6363
#' geom_point(na.rm = TRUE) +
64-
#' scale_x_continuous(name = "body", labels = scales::math_format(10^.x)) +
65-
#' scale_y_continuous(name = "brain", labels = scales::math_format(10^.x)) +
64+
#' scale_x_continuous(name = "body", labels = scales::label_math(10^.x)) +
65+
#' scale_y_continuous(name = "brain", labels = scales::label_math(10^.x)) +
6666
#' theme_bw() + theme(panel.grid.minor = element_blank())
6767
#'
6868
#' b + annotation_logticks()

R/axis-secondary.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#' date_breaks = "6 hour",
7777
#' sec.axis = dup_axis(
7878
#' name = "Time of Day",
79-
#' labels = scales::time_format("%I %p")
79+
#' labels = scales::label_time("%I %p")
8080
#' )
8181
#' )
8282
#'
@@ -89,7 +89,7 @@
8989
#' sec.axis = sec_axis(
9090
#' ~ . + 8 * 3600,
9191
#' name = "GMT+8",
92-
#' labels = scales::time_format("%b %d %I %p")
92+
#' labels = scales::label_time("%b %d %I %p")
9393
#' )
9494
#' )
9595
#'

R/coord-map.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ CoordMap <- ggproto("CoordMap", Coord,
334334

335335

336336
mproject <- function(coord, x, y, orientation) {
337-
check_installed("mapproj", reason = "for `coord_map()`")
337+
check_installed("mapproj", reason = "for `coord_map()`.")
338338
suppressWarnings(mapproj::mapproject(x, y,
339339
projection = coord$projection,
340340
parameters = coord$params,

R/fortify-map.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fortify.map <- function(model, data, ...) {
7878
#' coord_map("albers", lat0 = 45.5, lat1 = 29.5)
7979
#' }
8080
map_data <- function(map, region = ".", exact = FALSE, ...) {
81-
check_installed("maps", reason = "for `map_data()`")
81+
check_installed("maps", reason = "for `map_data()`.")
8282
map_obj <- maps::map(map, region, exact = exact, plot = FALSE, fill = TRUE, ...)
8383
fortify(map_obj)
8484
}

R/fortify.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fortify.data.frame <- function(model, data, ...) model
1717
fortify.tbl_df <- function(model, data, ...) model
1818
#' @export
1919
fortify.tbl <- function(model, data, ...) {
20-
check_installed("dplyr", reason = "to work with `tbl` objects")
20+
check_installed("dplyr", reason = "to work with `tbl` objects.")
2121
dplyr::collect(model)
2222
}
2323
#' @export
@@ -29,7 +29,7 @@ fortify.function <- function(model, data, ...) model
2929
fortify.formula <- function(model, data, ...) as_function(model)
3030
#' @export
3131
fortify.grouped_df <- function(model, data, ...) {
32-
check_installed("dplyr", reason = "to work with `grouped_df` objects")
32+
check_installed("dplyr", reason = "to work with `grouped_df` objects.")
3333
model$.group <- dplyr::group_indices(model)
3434
model
3535
}

R/scale-continuous.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
#' y = seq(0, 1, length.out = 10)
5454
#' )
5555
#' p2 <- ggplot(df, aes(x, y)) + geom_point()
56-
#' p2 + scale_y_continuous(labels = scales::percent)
57-
#' p2 + scale_y_continuous(labels = scales::dollar)
58-
#' p2 + scale_x_continuous(labels = scales::comma)
56+
#' p2 + scale_y_continuous(labels = scales::label_percent())
57+
#' p2 + scale_y_continuous(labels = scales::label_dollar())
58+
#' p2 + scale_x_continuous(labels = scales::label_comma())
5959
#'
6060
#' # You can also override the default linear mapping by using a
6161
#' # transformation. There are three shortcuts:

R/scale-date.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ datetime_scale <- function(aesthetics, trans, palette,
308308
}
309309
if (!is.waive(date_labels)) {
310310
labels <- function(self, x) {
311-
tz <- if (is.null(self$timezone)) "UTC" else self$timezone
312-
date_format(date_labels, tz)(x)
311+
tz <- self$timezone %||% "UTC"
312+
label_date(date_labels, tz)(x)
313313
}
314314
}
315315

R/stat-binhex.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ StatBinhex <- ggproto("StatBinhex", Stat,
4848

4949
compute_group = function(data, scales, binwidth = NULL, bins = 30,
5050
na.rm = FALSE) {
51-
check_installed("hexbin", reason = "for `stat_bin_hex()`")
51+
check_installed("hexbin", reason = "for `stat_bin_hex()`.")
5252

5353
binwidth <- binwidth %||% hex_binwidth(bins, scales)
5454
wt <- data$weight %||% rep(1L, nrow(data))

R/stat-quantilemethods.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ StatQuantile <- ggproto("StatQuantile", Stat,
4949
compute_group = function(data, scales, quantiles = c(0.25, 0.5, 0.75),
5050
formula = NULL, xseq = NULL, method = "rq",
5151
method.args = list(), lambda = 1, na.rm = FALSE) {
52-
check_installed("quantreg", reason = "for `stat_quantile()`")
52+
check_installed("quantreg", reason = "for `stat_quantile()`.")
5353

5454
if (is.null(formula)) {
5555
if (method == "rqss") {

R/stat-summary-hex.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ StatSummaryHex <- ggproto("StatSummaryHex", Stat,
4545

4646
compute_group = function(data, scales, binwidth = NULL, bins = 30, drop = TRUE,
4747
fun = "mean", fun.args = list()) {
48-
check_installed("hexbin", reason = "for `stat_summary_hex()`")
48+
check_installed("hexbin", reason = "for `stat_summary_hex()`.")
4949

5050
binwidth <- binwidth %||% hex_binwidth(bins, scales)
5151
fun <- as_function(fun)

man/annotation_logticks.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/scale_continuous.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/sec_axis.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-guides.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ test_that("guide_axis() draws minor ticks correctly", {
500500
axis.minor.ticks.length.x.top = unit(-0.5, "cm"),
501501
axis.minor.ticks.length.x.bottom = unit(0.75, "cm"),
502502
axis.minor.ticks.length.y.right = unit(5, "cm")) +
503-
scale_x_continuous(labels = math_format()) +
503+
scale_x_continuous(labels = label_math()) +
504504
guides(
505505
# Test for styling and style inheritance
506506
x = guide_axis(minor.ticks = TRUE),

tests/testthat/test-scale_date.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ test_that("date scale draws correctly", {
2222
expect_doppelganger("scale_x_date(breaks = \"3 weeks\")",
2323
dt + scale_x_date(date_breaks = "3 weeks")
2424
)
25-
expect_doppelganger("scale_x_date(labels = date_format(\"%m/%d\"))",
26-
dt + scale_x_date(labels = date_format("%m/%d"))
25+
expect_doppelganger("scale_x_date(labels = label_date(\"%m/%d\"))",
26+
dt + scale_x_date(labels = label_date("%m/%d"))
2727
)
28-
expect_doppelganger("scale_x_date(labels = date_format(\"%W\"), \"week\")",
29-
dt + scale_x_date(labels = date_format("%W"), "week")
28+
expect_doppelganger("scale_x_date(labels = label_date(\"%W\"), \"week\")",
29+
dt + scale_x_date(labels = label_date("%W"), "week")
3030
)
3131

3232
dt <- ggplot(df, aes(price, dx)) + geom_line()

tests/testthat/test-scales-breaks-labels.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ test_that("minor breaks draw correctly", {
321321
ggplot(df, aes(x_date, y)) +
322322
geom_blank() +
323323
scale_x_date(
324-
labels = scales::date_format("%m/%d"),
324+
labels = scales::label_date("%m/%d"),
325325
breaks = scales::date_breaks("month"),
326326
minor_breaks = scales::date_breaks("week")
327327
) +

0 commit comments

Comments
 (0)