r4ds
r4ds copied to clipboard
Suggestion: replace `pwalk(list(...), ...)` by `walk2(..., ...)` in iteration chapter
Current code:
library(ggplot2)
plots <- mtcars %>%
split(.$cyl) %>%
map(~ggplot(., aes(mpg, wt)) + geom_point())
paths <- stringr::str_c(names(plots), ".pdf")
pwalk(list(paths, plots), ggsave, path = tempdir())
Suggestion (watch the last line):
library(ggplot2)
plots <- mtcars %>%
split(.$cyl) %>%
map(~ggplot(., aes(mpg, wt)) + geom_point())
paths <- stringr::str_c(names(plots), ".pdf")
walk2(paths, plots, ggsave, path = tempdir())
Rationale:
- simpler code
- no reason to use
pwalk()
while there are only 2 lists
Note:
I submitted PR #668 with typos corrections and I push to it whenever I find new typos. If you agreed with this change, I could push it to that PR as well.
Could you please do a new PR?