parent
2ae56e389d
commit
72e0f519dc
|
@ -862,18 +862,18 @@ x |>
|
||||||
```
|
```
|
||||||
|
|
||||||
`walk()` is generally not that useful compared to `walk2()` or `pwalk()`.
|
`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}
|
```{r}
|
||||||
#| eval: false
|
#| eval: false
|
||||||
|
library(tidyverse)
|
||||||
|
|
||||||
library(ggplot2)
|
|
||||||
plots <- mtcars |>
|
plots <- mtcars |>
|
||||||
split(.$cyl) |>
|
split(mtcars$cyl) |>
|
||||||
map(~ggplot(.x, aes(mpg, wt)) + geom_point())
|
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.
|
`walk()`, `walk2()` and `pwalk()` all invisibly return `.`, the first argument.
|
||||||
|
|
Loading…
Reference in New Issue