Skip to content

Commit

Permalink
Changed magrittr pipes to base pipe in examples (#1139)
Browse files Browse the repository at this point in the history
Fixes #1133
  • Loading branch information
cheryldietrich authored Aug 15, 2024
1 parent 49bb36b commit 72a4dcf
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ accessor(x[[1]])$foo
to the equivalent pluck:
```
x %>% pluck(1, accessor, "foo")
x |> pluck(1, accessor, "foo")
```
Expand Down Expand Up @@ -968,7 +968,7 @@ This is a compatibility release with dplyr 0.6.0.

* `set_names()` is a snake-case alternative to `setNames()` with stricter
equality checking, and more convenient defaults for pipes:
`x %>% set_names()` is equivalent to `setNames(x, x)` (#119).
`x |> set_names()` is equivalent to `setNames(x, x)` (#119).


## Row based functionals
Expand All @@ -980,7 +980,7 @@ functions.
* `map()` now always returns a list. Data frame support has been moved
to `map_df()` and `dmap()`. The latter supports sliced data frames
as a shortcut for the combination of `by_slice()` and `dmap()`:
`x %>% by_slice(dmap, fun, .collate = "rows")`. The conditional
`x |> by_slice(dmap, fun, .collate = "rows")`. The conditional
variants `dmap_at()` and `dmap_if()` also support sliced data frames
and will recycle scalar results to the slice size.

Expand Down
2 changes: 1 addition & 1 deletion R/deprec-when.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#'
#' @keywords internal
#' @examples
#' 1:10 %>%
#' 1:10 |>
#' when(
#' sum(.) <= 50 ~ sum(.),
#' sum(.) <= 100 ~ sum(.)/2,
Expand Down
8 changes: 4 additions & 4 deletions R/keep.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ compact <- function(.x, .p = identity) {
#' @export
#' @examples
#' x <- c(a = 1, b = 2, cat = 10, dog = 15, elephant = 5, e = 10)
#' x %>% keep_at(letters)
#' x %>% discard_at(letters)
#' x |> keep_at(letters)
#' x |> discard_at(letters)
#'
#' # Can also use a function
#' x %>% keep_at(~ nchar(.x) == 3)
#' x %>% discard_at(~ nchar(.x) == 3)
#' x |> keep_at(~ nchar(.x) == 3)
#' x |> discard_at(~ nchar(.x) == 3)
keep_at <- function(x, at) {
where <- where_at(x, at, user_env = caller_env())
x[where]
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ library(purrr)
mtcars |>
split(mtcars$cyl) |> # from base R
map(\(df) lm(mpg ~ wt, data = df)) |>
map(summary) %>%
map(summary) |>
map_dbl("r.squared")
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ library(purrr)
mtcars |>
split(mtcars$cyl) |> # from base R
map(\(df) lm(mpg ~ wt, data = df)) |>
map(summary) %>%
map(summary) |>
map_dbl("r.squared")
#> 4 6 8
#> 0.5086326 0.4645102 0.4229655
Expand Down
8 changes: 4 additions & 4 deletions man/keep_at.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/when.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions purrr.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

UseNativePipeOperator: Yes
8 changes: 4 additions & 4 deletions vignettes/base.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ The pipe is particularly compelling when working with longer transformations.
For example, the following code splits `mtcars` up by `cyl`, fits a linear model, extracts the coefficients, and extracts the first one (the intercept).

```{r, eval = modern_r}
mtcars %>%
split(mtcars$cyl) %>%
map(\(df) lm(mpg ~ wt, data = df)) %>%
map(coef) %>%
mtcars |>
split(mtcars$cyl) |>
map(\(df) lm(mpg ~ wt, data = df))|>
map(coef) |>
map_dbl(1)
```
2 changes: 1 addition & 1 deletion vignettes/other-langs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ purrr draws inspiration from many related tools:

However, the goal of purrr is not to try and simulate a purer functional programming language in R; we don't want to implement a second-class version of Haskell in R. The goal is to give you similar expressiveness to an FP language, while allowing you to write code that looks and works like R:

* Instead of point free (tacit) style, we use the pipe, `%>%`, to write code
* Instead of point free (tacit) style, we use the pipe, `|>`, to write code
that can be read from left to right.

* Instead of currying, we use `...` to pass in extra arguments.
Expand Down

0 comments on commit 72a4dcf

Please sign in to comment.