flat-map2: Flat map over multiple inputs simultaneously

Description Usage Arguments Examples

Description

These functions are variants of flat_map_vec() that iterate over multiple arguments simultaneously.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
flat_map2_vec(.x, .y, .f, ..., .ptype = NULL, .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_map2_lst(.x, .y, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_map2_dbl(.x, .y, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_map2_int(.x, .y, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_map2_chr(.x, .y, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_map2_lgl(.x, .y, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_pmap_vec(.l, .f, ..., .ptype = NULL, .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_pmap_lst(.l, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_pmap_dbl(.l, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_pmap_int(.l, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_pmap_chr(.l, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

flat_pmap_lgl(.l, .f, ..., .name_spec = NULL,
  .name_repair = c("minimal", "unique", "check_unique", "universal"))

Arguments

.x, .y

Vectors of the same length. A vector of length 1 will be recycled.

.f

A function, formula, or vector (not necessarily atomic).

If a function, it is used as is.

If a formula, e.g. ~ .x + 2, it is converted to a function. There are three ways to refer to the arguments:

  • For a single argument function, use .

  • For a two argument function, use .x and .y

  • For more arguments, use ..1, ..2, ..3 etc

This syntax allows you to create very compact anonymous functions.

If character vector, numeric vector, or list, it is converted to an extractor function. Character vectors index by name and numeric vectors index by position; use a list to index by position and name at different levels. If a component is not present, the value of .default will be returned.

...

Additional arguments passed on to the mapped function.

.ptype

If NULL, the default, the output type is determined by computing the common type across all elements of ....

Alternatively, you can supply .ptype to give the output known type. If getOption("vctrs.no_guessing") is TRUE you must supply this value: this is a convenient way to make production code demand fixed types.

.name_spec

A name specification for combining inner and outer names. This is relevant for inputs passed with a name, when these inputs are themselves named, like outer = c(inner = 1), or when they have length greater than 1: outer = 1:2. By default, these cases trigger an error. You can resolve the error by providing a specification that describes how to combine the names or the indices of the inner vector with the name of the input. This specification can be:

  • A function of two arguments. The outer name is passed as a string to the first argument, and the inner names or positions are passed as second argument.

  • An anonymous function as a purrr-style formula.

  • A glue specification of the form "{outer}_{inner}".

See the name specification topic.

.name_repair

How to repair names, see repair options in vec_as_names().

.l

A list of vectors, such as a data frame. The length of .l determines the number of arguments that .f will be called with. List names will be used if present.

Examples

1
2
# Interleave vectors (but this isn't that efficient)
flat_map2_dbl(1:5, 6:10, ~c(.x, .y))

DavisVaughan/flatcat documentation built on Oct. 30, 2019, 5 p.m.