flat-map2-df: Flat map multiple inputs simultaneouly and convert to a data...

Description Usage Arguments Examples

Description

These functions are variants of flat_map_dfr() and flat_map_dfc() that iterate over multiple arguments simultaneously.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
flat_map2_dfr(.x, .y, .f, ..., .ptype = NULL, .names_to = NULL,
  .name_repair = c("unique", "universal", "check_unique"))

flat_map2_dfc(.x, .y, .f, ..., .ptype = NULL, .size = NULL,
  .name_repair = c("unique", "universal", "check_unique", "minimal"))

flat_pmap_dfr(.l, .f, ..., .ptype = NULL, .names_to = NULL,
  .name_repair = c("unique", "universal", "check_unique"))

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

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.

.names_to

Optionally, the name of a column where the names of ... arguments are copied. These names are useful to identify which row comes from which input. If supplied and ... is not named, an integer column is used to identify the rows.

.name_repair

One of "unique", "universal", or "check_unique". See vec_as_names() for the meaning of these options.

With vec_rbind(), the repair function is applied to all inputs separately. This is because vec_rbind() needs to align their columns before binding the rows, and thus needs all inputs to have unique names. On the other hand, vec_cbind() applies the repair function after all inputs have been concatenated together in a final data frame. Hence vec_cbind() allows the more permissive minimal names repair.

.size

If, NULL, the default, will determine the number of rows in vec_cbind() output by using the standard recycling rules.

Alternatively, specify the desired number of rows, and any inputs of length 1 will be recycled appropriately.

.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
flat_map2_dfr(list(1, 2:3), list(4, 5:6), ~data.frame(x = .x, y = .y))

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