map2_struct: Map over two inputs

View source: R/standalone-struct-list.R

map2_structR Documentation

Map over two inputs

Description

These functions are variants of map() that iterate over two arguments at a time.

Usage

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

Arguments

.x, .y

A pair of vectors, usually the same length. If not, a vector of length 1 will be recycled to the length of the other.

.f

A function, specified in one of the following ways:

  • A named function.

  • An anonymous function, e.g. ⁠\(x, y) x + y⁠ or function(x, y) x + y.

  • A formula, e.g. ~ .x + .y. You must use .x to refer to the current element of x and .y to refer to the current element of y. Only recommended if you require backward compatibility with older versions of R.

...

Additional arguments passed on to the mapped function.

We now generally recommend against using ... to pass additional (constant) arguments to .f. Instead use a shorthand anonymous function:

# Instead of
x |> map(f, 1, 2, collapse = ",")
# do:
x |> map(\(x) f(x, 1, 2, collapse = ","))

This makes it easier to understand which arguments belong to which function and will tend to yield better error messages.

.progress

Whether to show a progress bar. Use TRUE to turn on a basic progress bar, use a string to give it a name, or see progress_bars for more details.

Value

a 'struct_list'


terminological/ggrrr documentation built on June 15, 2024, 6:35 a.m.