Skip to content

Commit 84d202f

Browse files
committed
Convert some simple anonymous functions to shorthand
1 parent cc7110f commit 84d202f

File tree

6 files changed

+7
-9
lines changed

6 files changed

+7
-9
lines changed

R/aes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ NULL
8888
#'
8989
#' # Note that users of your wrapper can use their own functions in the
9090
#' # quoted expressions and all will resolve as it should!
91-
#' cut3 <- function(x) cut_number(x, 3)
91+
#' cut3 <- \(x) cut_number(x, 3)
9292
#' scatter_by(mtcars, cut3(disp), drat)
9393
aes <- function(x, y, ...) {
9494
xs <- arg_enquos("x")

R/annotation-logticks.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@
4343
#' a <- ggplot(msleep, aes(bodywt, brainwt)) +
4444
#' geom_point(na.rm = TRUE) +
4545
#' scale_x_log10(
46-
#' breaks = scales::trans_breaks("log10", function(x) 10^x),
46+
#' breaks = scales::trans_breaks("log10", \(x) 10^x),
4747
#' labels = scales::trans_format("log10", scales::math_format(10^.x))
4848
#' ) +
4949
#' scale_y_log10(
50-
#' breaks = scales::trans_breaks("log10", function(x) 10^x),
50+
#' breaks = scales::trans_breaks("log10", \(x) 10^x),
5151
#' labels = scales::trans_format("log10", scales::math_format(10^.x))
5252
#' ) +
5353
#' theme_bw()

R/geom-function.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@
4242
#' geom_function(aes(colour = "t, df = 1"), fun = dt, args = list(df = 1))
4343
#'
4444
#' # Using a custom anonymous function
45-
#' base + geom_function(fun = function(x) 0.5 * exp(-abs(x)))
45+
#' base + geom_function(fun = \(x) 0.5 * exp(-abs(x)))
4646
#' # or using lambda syntax:
4747
#' # base + geom_function(fun = ~ 0.5 * exp(-abs(.x)))
48-
#' # or in R4.1.0 and above:
49-
#' # base + geom_function(fun = \(x) 0.5 * exp(-abs(x)))
5048
#' # or using a custom named function:
5149
#' # f <- function(x) 0.5 * exp(-abs(x))
5250
#' # base + geom_function(fun = f)

R/geom-histogram.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
#' # different ranges because the function will be called once per facet
133133
#' ggplot(economics_long, aes(value)) +
134134
#' facet_wrap(~variable, scales = 'free_x') +
135-
#' geom_histogram(binwidth = function(x) 2 * IQR(x) / (length(x)^(1/3)))
135+
#' geom_histogram(binwidth = \(x) 2 * IQR(x) / (length(x)^(1/3)))
136136
geom_histogram <- function(mapping = NULL, data = NULL,
137137
stat = "bin", position = "stack",
138138
...,

R/labeller.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#' p + facet_grid(. ~ cyl2, labeller = label_parsed)
8686
#'
8787
#' # Include optional argument in label function
88-
#' p + facet_grid(. ~ cyl, labeller = function(x) label_both(x, sep = "="))
88+
#' p + facet_grid(. ~ cyl, labeller = \(x) label_both(x, sep = "="))
8989
#' }
9090
#' @name labellers
9191
NULL

R/stat-summary-2d.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#' d + stat_summary_2d()
3636
#'
3737
#' # Specifying function
38-
#' d + stat_summary_2d(fun = function(x) sum(x^2))
38+
#' d + stat_summary_2d(fun = \(x) sum(x^2))
3939
#' d + stat_summary_2d(fun = ~ sum(.x^2))
4040
#' d + stat_summary_2d(fun = var)
4141
#' d + stat_summary_2d(fun = "quantile", fun.args = list(probs = 0.1))

0 commit comments

Comments
 (0)