Skip to contents

Map over leaves of two nested lists

Usage

list_map2(.x, .y, .f, ..., .progress = FALSE)

Arguments

.x

A nested list to traverse.

Lists are traversed recursively. Non-list objects are treated as leaves. Data frames are not traversed and are treated as leaf values.

.y

A nested list. Must have the same structure as .x.

.f

A function, formula, or function-like object coercible by rlang::as_function(). Additional arguments supplied through ... are passed on to .f.

...

Additional arguments passed to .f.

.progress

Whether to show a progress

Use TRUE to turn on a basic progress, use a string to give it a name, or use a list to customize the progress bar (see ?cli::cli_progress_bar and https://cli.r-lib.org/articles/progress-advanced.html#cli_progress_bar for details).

Examples

# \donttest{
x <- list(
  a = 1,
  b = list(
    x = 1,
    y = list(i = 1, j = 2)
  )
)
x2 <- list_map2(x, x, ~ {.x + .y})
# $a
# [1] 2
#
# $b
# $b$x
# [1] 2
#
# $b$y
# $b$y$i
# [1] 2
#
# $b$y$j
# [1] 4
# }