Comparing purrr and lapply comes down to convenience and speed .
1. purrr::map syntactically more convenient than lapply
extract second list item
map(list, 2)
which is like @F. PrivΓ© pointed out the same as:
map(list, function(x) x[[2]])
with lapply
lapply(list, 2)
we need to pass an anonymous function ...
lapply(list, function(x) x[[2]])
... or, as @RichScriven pointed out, we pass [[ as an argument to lapply
lapply(list, '[[', 2)
Therefore, if you find that you apply functions to many lists using lapply , and are tired of either defining a user-defined function or writing an anonymous function, convenience is one of the reasons to switch to purrr .
2. Map type-specific functions are just a lot of lines of code
map_chr()map_lgl()map_int()map_dbl()map_df() - my favorite, returns a data frame.
Each of these mapping functions of a particular type returns an atomic list (vector), not the lists returned by map() and lapply() . If you are dealing with nested lists of atomic vectors inside, you can use these type-specific display functions to directly extract vectors and force the vectors to be converted directly to vectors int, dbl, chr. The basic version of R will look something like this: as.numeric(sapply(...)) , as.character(sapply(...)) , etc. This gives purrr one more point for convenience and functionality.
3. Convenience aside, lapply , [slightly] faster than map
Using convenient purrr functions like @F. Prive noted that he slows down the processing a little. Let each of the 4 cases that I presented above be chased.
# devtools::install_github("jennybc/repurrrsive") library(repurrrsive) library(purrr) library(microbenchmark) library(ggplot2) mbm <- microbenchmark( lapply = lapply(got_chars[1:4], function(x) x[[2]]), lapply_2 = lapply(got_chars[1:4], '[[', 2), map_shortcut = map(got_chars[1:4], 2), map = map(got_chars[1:4], function(x) x[[2]]), times = 100 ) autoplot(mbm)

And the winner is ....
lapply(list, '[[', 2)
In general, if you need base::lapply speed: base::lapply (although it is not much faster)
For simple syntax and expressibility: purrr::map
This excellent purrr tutorial on purrr emphasizes the convenience of not explicitly writing anonymous functions when using purrr and the benefits of map type-dependent functions.