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.
Syntax
walk(.x, .f, ..., .progress = FALSE)
Parameters
- .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.
Visual representation
Example
library(purrr)
cars <- list("bmw", "audi", "mercedez")
walk(cars, print)
Output
[1] "bmw"
[1] "audi"
[1] "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.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.