| compat-map {mlr3misc} | R Documentation |
Apply Functions in the spirit of 'purrr'
Description
map-like functions, similar to the ones implemented in purrr:
-
map()returns the results of.fapplied to.xas list. If.fis not a function,mapwill call[[on all elements of.xusing the value of.fas index. -
imap()applies.fto each value of.x(passed as first argument) and its name (passed as second argument). If.xdoes not have names, a sequence along.xis passed as second argument instead. -
pmap()expects.xto be a list of vectors of equal length, and then applies.fto the first element of each vector of.x, then the second element of.x, and so on. -
map_if()applies.fto each element of.xwhere the predicate.pevaluates toTRUE. -
map_at()applies.fto each element of.xreferenced by.at. All other elements remain unchanged. -
keep()keeps those elements of.xwhere predicate.pevaluates toTRUE. -
discard()discards those elements of.xwhere predicate.pevaluates toTRUE. -
every()isTRUEif predicate.pevaluates toTRUEfor each.x. -
some()isTRUEif predicate.pevaluates toTRUEfor at least one.x. -
detect()returns the first element where predicate.pevaluates toTRUE. -
walk(),iwalk()andpwalk()are the counterparts tomap(),imap()andpmap(), but just visit (or change by reference) the elements of.x. They return input.xinvisibly.
Additionally, the functions map(), imap() and pmap() have type-safe variants with the following suffixes:
-
*_lgl()returns alogical(length(.x)). -
*_int()returns ainteger(length(.x)). -
*_dbl()returns adouble(length(.x)). -
*_chr()returns acharacter(length(.x)). -
*_br()returns an object where the results of.fare put together withbase::rbind(). -
*_bc()returns an object where the results of.fare put together withbase::cbind(). -
*_dtr()returns adata.table::data.table()where the results of.fare put together in anbase::rbind()fashion. -
*_dtc()returns adata.table::data.table()where the results of.fare put together in anbase::cbind()fashion.
Usage
map(.x, .f, ...)
map_lgl(.x, .f, ...)
map_int(.x, .f, ...)
map_dbl(.x, .f, ...)
map_chr(.x, .f, ...)
map_br(.x, .f, ...)
map_bc(.x, .f, ...)
map_dtr(.x, .f, ..., .fill = FALSE, .idcol = NULL)
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, .idcol = NULL)
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, .idcol = NULL)
imap_dtc(.x, .f, ...)
keep(.x, .f, ...)
discard(.x, .p, ...)
map_if(.x, .p, .f, ...)
## Default S3 method:
map_if(.x, .p, .f, ...)
map_at(.x, .at, .f, ...)
every(.x, .p, ...)
some(.x, .p, ...)
detect(.x, .p, ...)
walk(.x, .f, ...)
iwalk(.x, .f, ...)
pwalk(.x, .f, ...)
Arguments
.x |
( |
.f |
( |
... |
( |
.fill |
( |
.idcol |
( |
.p |
( |
.at |
( |