purrr 0.2.0
New functions
- There are two handy infix functions:
accumulate()
has been added to handle recursive folding. It is shortand
forReduce(f, .x, accumulate = TRUE)
and follows a similar syntax to
reduce()
(#145). A right-hand versionaccumulate_right()
was also added.map_df()
row-binds output together. It's the equivalent ofplyr::ldply()
(#127)flatten()
is now type-stable and always returns a list. To return a simpler
vector, useflatten_lgl()
,flatten_int()
,flatten_dbl()
,
flatten_chr()
, orflatten_df()
.invoke()
has been overhauled to be more useful: it now works similarly
tomap_call()
when.x
is NULL, and hencemap_call()
has been
deprecated.invoke_map()
is a vectorised complement toinvoke()
(#125),
and comes with typed variantsinvoke_map_lgl()
,invoke_map_int()
,
invoke_map_dbl()
,invoke_map_chr()
, andinvoke_map_df()
.transpose()
replaceszip2()
,zip3()
, andzip_n()
(#128).
The name more clearly reflects the intent (transposing the first and second
levels of list). It no longer has fields argument or the.simplify
argument;
instead use the newsimplify_all()
function.safely()
,quietly()
, andpossibly()
are experimental functions
for working with functions with side-effects (e.g. printed output,
messages, warnings, and errors) (#120).safely()
is a version oftry()
that modifies a function (rather than an expression), and always returns a
list with two components,result
anderror
.list_along()
andrep_along()
generalise the idea ofseq_along()
.
(#122).is_null()
is the snake-case version ofis.null()
.pmap()
(parallel map) replacesmap_n()
(#132), and has typed-variants
suffixedpmap_lgl()
,pmap_int()
,pmap_dbl()
,pmap_chr()
, and
pmap_df()
.set_names()
is a snake-case alternative tosetNames()
with stricter
equality checking, and more convenient defaults for pipes:
x %>% set_names()
is equivalent tosetNames(x, x)
(#119).
Row based functionals
We are still figuring out what belongs in dplyr and what belongs in purrr. Expect much experimentation and many changes with these functions.
map()
now always returns a list. Data frame support has been moved
tomap_df()
anddmap()
. The latter supports sliced data frames
as a shortcut for the combination ofby_slice()
anddmap()
:
x %>% by_slice(dmap, fun, .collate = "rows")
. The conditional
variantsdmap_at()
anddmap_if()
also support sliced data frames
and will recycle scalar results to the slice size.map_rows()
has been renamed toinvoke_rows()
. As other
rows-based functionals, it collates results inside lists by default,
but with column collation this function is equivalent to
plyr::mdply()
.- The rows-based functionals gain a
.to
option to name the output
column as well as a.collate
argument. The latter allows to
collate the output in lists (by default), on columns or on
rows. This makes these functions more flexible and more predictable.
Bug fixes and minor changes
as_function()
, which converts formulas etc to functions, is now
exported (#123).rerun()
is correctly scoped (#95)update_list()
can now modify an element calledx
(#98).map*()
now use custom C code, rather than relying onlapply()
,mapply()
etc. The performance characteristcs are very similar, but it allows us greater
control over the output (#118).map_lgl()
now has second argument.f
, not.p
(#134).
Deprecated functions
flatmap()
-> usemap()
followed by the appropriateflatten()
.map_call()
->invoke()
.map_n()
->pmap()
;walk_n()
->pwalk()
.map3(x, y, z)
->map_n(list(x, y, z))
;walk3(x, y, z) ->
pwalk(list(x, y, z))`