Skip to content

Commit cc7110f

Browse files
committed
replace %>% with |>
1 parent 4b129b4 commit cc7110f

File tree

10 files changed

+40
-40
lines changed

10 files changed

+40
-40
lines changed

R/geom-map.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ NULL
5555
#'
5656
#' crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
5757
#'
58-
#' # Equivalent to crimes %>% tidyr::pivot_longer(Murder:Rape)
58+
#' # Equivalent to crimes |> tidyr::pivot_longer(Murder:Rape)
5959
#' vars <- lapply(names(crimes)[-1], function(j) {
6060
#' data.frame(state = crimes$state, variable = j, value = crimes[[j]])
6161
#' })

R/utilities-tidy-eval.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#'
2424
#' ```
2525
#' my_function <- function(data, var, ...) {
26-
#' data %>%
27-
#' group_by(...) %>%
26+
#' data |>
27+
#' group_by(...) |>
2828
#' summarise(mean = mean({{ var }}))
2929
#' }
3030
#' ```
@@ -43,8 +43,8 @@
4343
#' dots <- enquos(...)
4444
#'
4545
#' # Inject
46-
#' data %>%
47-
#' group_by(!!!dots) %>%
46+
#' data |>
47+
#' group_by(!!!dots) |>
4848
#' summarise(mean = mean(!!var))
4949
#' }
5050
#' ```
@@ -60,7 +60,7 @@
6060
#'
6161
#' ```
6262
#' my_var <- "disp"
63-
#' mtcars %>% summarise(mean = mean(.data[[my_var]]))
63+
#' mtcars |> summarise(mean = mean(.data[[my_var]]))
6464
#' ```
6565
#'
6666
#' * Another tidy eval operator is `:=`. It makes it possible to use
@@ -72,7 +72,7 @@
7272
#' my_function <- function(data, var, suffix = "foo") {
7373
#' # Use `{{` to tunnel function arguments and the usual glue
7474
#' # operator `{` to interpolate plain strings.
75-
#' data %>%
75+
#' data |>
7676
#' summarise("{{ var }}_mean_{suffix}" := mean({{ var }}))
7777
#' }
7878
#' ```
@@ -87,7 +87,7 @@
8787
#' my_function <- function(data, var, suffix = "foo") {
8888
#' var <- enquo(var)
8989
#' prefix <- as_label(var)
90-
#' data %>%
90+
#' data |>
9191
#' summarise("{prefix}_mean_{suffix}" := mean(!!var))
9292
#' }
9393
#' ```

man/geom_map.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tidyeval.Rd

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

tests/testthat/test-facet-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ test_that("facet variables", {
230230
test_that("facet gives clear error if ", {
231231
df <- data_frame(x = 1)
232232
expect_snapshot_error(print(ggplot(df, aes(x)) + facet_grid(x ~ x)))
233-
expect_snapshot_error(print(ggplot(df, aes(x)) %>% facet_grid(. ~ x)))
233+
expect_snapshot_error(print(ggplot(df, aes(x)) |> facet_grid(. ~ x)))
234234
expect_snapshot_error(print(ggplot(df, aes(x)) + facet_grid(list(1, 2, 3))))
235235
expect_snapshot_error(print(ggplot(df, aes(x)) + facet_grid(vars(x), "free")))
236236
})

tests/testthat/test-stat-bin.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ test_that("fuzzy breaks are used when cutting", {
7373
p <- ggplot(df, aes(x)) +
7474
geom_histogram(binwidth = 0.1, boundary = 0.1, closed = "left")
7575

76-
bins <- get_layer_data(p) %>% subset(count > 0) %>% .[1:5]
76+
bins <- get_layer_data(p) |> subset(count > 0) |> head(5)
7777
expect_equal(bins$count, c(1, 1, 1, 1))
7878
})
7979

vignettes/articles/faq-annotation.Rmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ Note that we expanded the y axis limit to get the numbers to fit on the plot.
142142
```{r}
143143
#| fig.alt: "A bar chart showing the number of cars for each of three types
144144
#| of drive train. The count values are displayed on top of the bars as text."
145-
mpg %>%
146-
dplyr::count(drv) %>%
145+
mpg |>
146+
dplyr::count(drv) |>
147147
ggplot(aes(x = drv, y = n)) +
148148
geom_col() +
149149
geom_text(aes(label = n), vjust = -0.5) +
@@ -184,7 +184,7 @@ ggplot(mpg, aes(x = class, fill = drv)) +
184184
You can first calculate the counts for each segment with `dplyr::count()`, which will place these values in a column called `n`.
185185

186186
```{r}
187-
mpg %>%
187+
mpg |>
188188
count(class, drv)
189189
```
190190

@@ -195,8 +195,8 @@ You can then pass this result directly to `ggplot()`, draw the segments with app
195195
#| types of cars. The fill colour of the bars indicate the type of drive
196196
#| train. In the middle of each filled part, the count value is displayed as
197197
#| text."
198-
mpg %>%
199-
count(class, drv) %>%
198+
mpg |>
199+
count(class, drv) |>
200200
ggplot(aes(x = class, fill = drv, y = n)) +
201201
geom_col() +
202202
geom_text(aes(label = n), size = 3, position = position_stack(vjust = 0.5))
@@ -226,9 +226,9 @@ One option is to calculate the proportions with `dplyr::count()` and then use `g
226226
```{r}
227227
#| fig.alt: "A bar chart showing the proportion of cars for each of three types
228228
#| of drive train."
229-
mpg %>%
230-
dplyr::count(drv) %>%
231-
mutate(prop = n / sum(n)) %>%
229+
mpg |>
230+
dplyr::count(drv) |>
231+
mutate(prop = n / sum(n)) |>
232232
ggplot(aes(x = drv, y = prop)) +
233233
geom_col()
234234
```

vignettes/articles/faq-bars.Rmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ poll <- tribble(
258258
You can first pivot the data longer to obtain a data frame with one row per party/opinion combination and a new column, `n`, for the number of responses that fall into that category.
259259

260260
```{r}
261-
poll_longer <- poll %>%
261+
poll_longer <- poll |>
262262
pivot_longer(
263263
cols = -party,
264264
names_to = "opinion",
@@ -318,12 +318,12 @@ Then, pass the resulting longer data frame to `ggplot()` group responses for eac
318318
#| fig.alt: "A grouped bar chart showing the number of responses to three
319319
#| questions. Within each question, two bars denote an 'Agree' or 'Disagree'
320320
#| response."
321-
survey %>%
321+
survey |>
322322
tidyr::pivot_longer(
323323
cols = -respondent,
324324
names_to = "question",
325325
values_to = "response"
326-
) %>%
326+
) |>
327327
ggplot(aes(x = question, fill = response)) +
328328
geom_bar(position = "dodge")
329329
```
@@ -344,9 +344,9 @@ Then, you can pass the resulting data frame to `ggplot()` and plot bars using `g
344344
```{r}
345345
#| fig.alt: "A bar chart showing the average highway miles per gallon for
346346
#| three types of drive train."
347-
mpg %>%
348-
group_by(drv) %>%
349-
summarise(mean_hwy = mean(hwy)) %>%
347+
mpg |>
348+
group_by(drv) |>
349+
summarise(mean_hwy = mean(hwy)) |>
350350
ggplot(aes(x = drv, y = mean_hwy)) +
351351
geom_col()
352352
```

vignettes/articles/faq-faceting.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ First, calculate these means and save them in a new data frame.
121121
```{r}
122122
library(dplyr)
123123
124-
mpg_summary <- mpg %>%
125-
group_by(drv) %>%
124+
mpg_summary <- mpg |>
125+
group_by(drv) |>
126126
summarise(hwy_mean = mean(hwy))
127127
128128
mpg_summary

vignettes/articles/faq-reordering.Rmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ Now the blue circle is over the yellow triangle since 0.01 comes after 0 and sim
234234
#| four x-positions, of which two are very distinct. Every point has a distinct
235235
#| shape and colour. A blue circle is plotted on top of a yellow triangle. A
236236
#| red square is plotted on top of a black asterisk."
237-
df_arranged <- df %>% dplyr::arrange(x)
237+
df_arranged <- df |> dplyr::arrange(x)
238238
239-
df_arranged %>%
239+
df_arranged |>
240240
ggplot(aes(x = x, y = y, fill = fill, shape = shape)) +
241241
geom_point(size = 8) +
242242
scale_shape_identity() +
@@ -257,14 +257,14 @@ If you wanted to make sure that the observation identified with an asterisk is a
257257
#| asterisk is plotted on top of a red square."
258258
259259
ggplot(mapping = aes(x = x, y = y, fill = fill, shape = shape)) +
260-
geom_point(data = df %>% filter(shape != "asterisk"), size = 8) +
261-
geom_point(data = df %>% filter(shape == "asterisk"), size = 8) +
260+
geom_point(data = df |> filter(shape != "asterisk"), size = 8) +
261+
geom_point(data = df |> filter(shape == "asterisk"), size = 8) +
262262
scale_shape_identity() +
263263
scale_fill_identity()
264264
265265
ggplot(mapping = aes(x = x, y = y, fill = fill, shape = shape)) +
266-
geom_point(data = df_arranged %>% filter(shape != "asterisk"), size = 8) +
267-
geom_point(data = df_arranged %>% filter(shape == "asterisk"), size = 8) +
266+
geom_point(data = df_arranged |> filter(shape != "asterisk"), size = 8) +
267+
geom_point(data = df_arranged |> filter(shape == "asterisk"), size = 8) +
268268
scale_shape_identity() +
269269
scale_fill_identity()
270270
```

0 commit comments

Comments
 (0)