diff --git a/iteration.qmd b/iteration.qmd index 2e7148a..b37b630 100644 --- a/iteration.qmd +++ b/iteration.qmd @@ -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.