The walk() function from the purrr package is used to perform actions like writing files and printing plots. The function is applied to each list element, and the result is discarded.
walk(.x, .f, ..., .progress = FALSE)
- .x: It is a list or atomic vector.
- .f: It is a function.
- ...: Additional arguments passed on to the mapped function.
- .progress: Whether to show a progress bar. Use TRUE to turn on a basic progress bar.
library(purrr) cars <- list("bmw", "audi", "mercedez") walk(cars, print)
 "bmw"  "audi"  "mercedez"
Difference between walk() and map() functions
The main difference between the walk() and map() functions is that the walk() function is used when you want to act on each element of a list or vector, such as printing or writing to a file. Still, you don’t want to return anything.
On the other hand, the map() function is used when you want to apply a function to each element of a list or vector and return the results as a new list or vector.
For example, if you have a list of numbers and want to square each number and return the results as a new list, you can use map() to apply the ^2 function to each number.