Use walk2 instead of pwalk

Fixes #675
This commit is contained in:
Hadley Wickham 2022-08-30 08:55:08 -05:00
parent 2ae56e389d
commit 72e0f519dc
1 changed files with 5 additions and 5 deletions

View File

@ -862,18 +862,18 @@ x |>
```
`walk()` is generally not that useful compared to `walk2()` or `pwalk()`.
For example, if you had a list of plots and a vector of file names, you could use `pwalk()` to save each file to the corresponding location on disk:
For example, if you had a list of plots and a vector of file names, you could use `walk2()` to save each file to the corresponding location on disk:
```{r}
#| eval: false
library(tidyverse)
library(ggplot2)
plots <- mtcars |>
split(.$cyl) |>
split(mtcars$cyl) |>
map(~ggplot(.x, aes(mpg, wt)) + geom_point())
paths <- stringr::str_c(names(plots), ".pdf")
paths <- str_c(names(plots), ".pdf")
pwalk(list(paths, plots), ggsave, path = tempdir())
walk2(paths, plots, ggsave, path = tempdir())
```
`walk()`, `walk2()` and `pwalk()` all invisibly return `.`, the first argument.