compat-map

0th

Percentile

Apply Functions in the spirit of 'purrr'

map-like functions, similar to the ones implemented in purrr:

  • map() returns the results of .f applied to .x as list. If .f is not a function, map will call [[ on all elements of .x using the value of .f as index.

  • imap() applies .f to each value of .x (passed as first argument) and its name (passed as second argument). If .x does not have names, a sequence along .x is passed as second argument instead.

  • pmap() expects .x to be a list of vectors of equal length, and then applies .f to the first element of each vector of .x, then the second element of .x, and so on.

  • map_if() applies .f to each element of .x where the predicate .p evaluates to TRUE.

  • map_at() applies .f to each element of .x referenced by .at. All other elements remain unchanged.

  • keep() keeps those elements of .x where predicate .p evaluates to TRUE.

  • discard() discards those elements of .x where predicate .p evaluates to TRUE.

  • every() is TRUE if predicate .p evaluates to TRUE for each .x.

  • some() is TRUE if predicate .p evaluates to TRUE for at least one .x.

Additionally, the functions map(), imap() and pmap have type-safe variants with the following suffixes:

  • *_lgl() returns a logical(length(.x)).

  • *_int() returns a integer(length(.x)).

  • *_dbl() returns a double(length(.x)).

  • *_chr() returns a character(length(.x)).

  • *_dtr() returns a data.table::data.table() where the results of .f are put together in an base::rbind() fashion.

  • *_dtc() returns a data.table::data.table() where the results of .f are put together in an base::cbind() fashion.

Usage
map(.x, .f, ...)

map_lgl(.x, .f, ...)

map_int(.x, .f, ...)

map_dbl(.x, .f, ...)

map_chr(.x, .f, ...)

map_dtr(.x, .f, ..., .fill = FALSE)

map_dtc(.x, .f, ...)

pmap(.x, .f, ...)

pmap_lgl(.x, .f, ...)

pmap_int(.x, .f, ...)

pmap_dbl(.x, .f, ...)

pmap_chr(.x, .f, ...)

pmap_dtr(.x, .f, ..., .fill = FALSE)

pmap_dtc(.x, .f, ...)

imap(.x, .f, ...)

imap_lgl(.x, .f, ...)

imap_int(.x, .f, ...)

imap_dbl(.x, .f, ...)

imap_chr(.x, .f, ...)

imap_dtr(.x, .f, ..., .fill = FALSE)

imap_dtc(.x, .f, ...)

keep(.x, .f, ...)

discard(.x, .p, ...)

map_if(.x, .p, .f, ...)

map_at(.x, .at, .f, ...)

every(.x, .p, ...)

some(.x, .p, ...)

Arguments
.x

:: (list() or atomic vector).

.f

:: (function | character() | integer()) Function to apply, or element to extract by name (if .f is character()) or position (if .f is integer()).

...

:: any Additional arguments passed down to .f or .p.

.fill

:: logical(1) Passed down to data.table::rbindlist().

.p

:: (function() | logical()) Predicate function.

.at

:: (character() | integer() | logical()) Index vector.

Aliases
  • compat-map
  • map
  • map_lgl
  • map_int
  • map_dbl
  • map_chr
  • map_dtr
  • map_dtc
  • pmap
  • pmap_lgl
  • pmap_int
  • pmap_dbl
  • pmap_chr
  • pmap_dtr
  • pmap_dtc
  • imap
  • imap_lgl
  • imap_int
  • imap_dbl
  • imap_chr
  • imap_dtr
  • imap_dtc
  • keep
  • discard
  • map_if
  • map_at
  • every
  • some
Documentation reproduced from package mlr3misc, version 0.1.0, License: LGPL-3

Community examples

Looks like there are no examples yet.