Skip to contents

lmap*() are similar to lapply(), but they map over subset .x[i] instead of element .x[[i]]. It allows .f to access the attributes of the encapsulating list. This is useful for operation on the sfc column in an sf data.frame. purrr::lmap() does similar things, but it forces the output to be a list.

mclmap*() are parallelized versions of lmap*().

Usage

lmap_lst(.x, .f, mode = c("list", "integer", "double", "character", "logical"))

lmap_lgl(.x, .f)

lmap_int(.x, .f)

lmap_dbl(.x, .f)

lmap_chr(.x, .f)

lmap_vec(.x, .f, .ptype = NULL)

mclmap_lst(.x, .f, ...)

mclmap_lgl(.x, .f, ...)

mclmap_int(.x, .f, ...)

mclmap_dbl(.x, .f, ...)

mclmap_chr(.x, .f, ...)

mclmap_vec(.x, .f, ..., .ptype = NULL)

Arguments

.x

A list.

.f

A function to apply to each subset of .x.

mode

Output type.

.ptype

A prototype for the output vector.

...

Additional arguments passed to parallel::mclapply().

Value

A vector of the same length as .x. The suffix of the function name denotes the output type. *_vec() applies purrr::list_simplify() before returning.

See also

Examples

x = list(a = 1.0, b = 2.0)
lmap_lst(x, unlist)
#> $a
#> a 
#> 1 
#> 
#> $b
#> b 
#> 2 
#> 

lmap_lgl(x, is.list)
#>    a    b 
#> TRUE TRUE 

lmap_int(x, length)
#> a b 
#> 1 1 

lmap_dbl(x, unlist)
#> a b 
#> 1 2 

lmap_chr(x, names)
#>   a   b 
#> "a" "b" 

lmap_vec(x, \(.x) .x[[1L]] + 2i)
#>    a    b 
#> 1+2i 2+2i