.fare now correctly passed through internal
reduce2_impl(), in keeping with the documentation and
reduce_right(). Previously, and incorrectly,
.fhad their behavior reversed. If you inverted
.fto make it works, you should now revert back the order.
paste2 <- function(x, y, sep = ".") paste(x, y, sep = sep) ## with purrr > 2.5 reduce2_right(letters[1:4], c("-", ".", "-"), paste2) ## with purrr <= 2.5 # error reduce2_right(.x = letters[1:4], .y = c("-", ".", "-"), .f = paste2) # error # working reduce2_right(.x = letters[1:4], .y = paste2, .f = c("-", ".", "-")) # working
pluck()no longer flattens lists of arguments. You can still do it manually with
!!!. This breaking change is for consistency with other dots-collecting functions of the tidyverse.
Removing elements from lists using
list_modify()is soft-deprecated. Please use the new
zap()sentinel reexported from rlang instead:
# Before: list_modify(x, foo = NULL) # After: list_modify(x, foo = zap())
This change is motivated by the ambiguity of
NULLas a deletion sentinel because
NULLis also a valid value in lists. In the future,
NULLwill set an element to
NULLrather than removing the element.
invoke()is soft-deprecated and replaced by the
exec()function, reexported from rlang.
exec()evaluates a function call built from its inputs and supports tidy dots:
# Before: invoke(mean, list(na.rm = TRUE), x = 1:10) # After exec(mean, 1:10, !!!list(na.rm = TRUE))
invoke_map()is soft-deprecated without replacement because it is more complex to understand than the corresponding code using
# Before: invoke_map(fns, list(args)) invoke_map(fns, list(args1, args2)) # After: map(fns, exec, !!!args) map2(fns, list(args1, args2), function(fn, args) exec(fn, !!!args))
rerun()is now in the questioning stage because we are no longer convinced NSE functions are a good fit for purrr. Also,
rerun(n, x)can just as easily be expressed as
map(1:n, ~ x)(with the added benefit of being passed the current index as argument to the lambda).
Minor improvements and fixes
By popular request,
at_depth()has been brought back as
modify_depth(), it applies a function at a specified level of a data structure. However, it transforms all traversed vectors up to
.depthto bare lists (#381).
modify_depth()now modifies atomic leaves as well. This makes
modify_depth(x, 1, fn)equivalent to
compose()now returns an identity function when called without inputs.
Functions created with
compose()now have the same formal parameters as the first function to be called. They also feature a more informative print method that prints all composed functions in turn (@egnha, #366).
list_modify()now supports the
zap()sentinel (reexported from rlang) to remove elements from lists. Consequently, removing elements with the ambiguous sentinel
The requirements of
list_merge()have been relaxed. Previously it required both the modified lists and the inputs to be either named or unnamed. This restriction now only applies to inputs in
.... When inputs are all named, they are matched to the list by name. When they are all unnamed, they are matched positionally. Otherwise, this is an error.
pluck()now dispatches properly with S3 vectors. The vector class must implement a
length()method for numeric indexing and a
names()method for string indexing.
modify_if(). They take an alternative function that is mapped over elements of the input for which the predicate function returns
pluck<-functions. They modify a data structure at an existing pluck location.
modify_in()function to map a function at a pluck location.
Functions taking predicates (
keep(), etc) now fail with an informative message when the return value is not
This is a breaking change for
some()which were documented to be more liberal in the values they accepted as logical (any vector was considered
TRUEif not a single
FALSEvalue, no matter its length). These functions signal soft-deprecation warnings instead of a hard failure.
pluck()now supports primitive functions (#404).
compose(). If set to
FALSE, the functions are composed from left to right rather than right to left.
chuck()function. This is a strict variant of
pluck()that throws errors when an element does not exist instead of returning
The tibble package is now in Suggests rather than Imports. This brings the hard dependency of purrr to just rlang and magrittr.
Fixed ordering of names returned by
accumulate_right()output. They now correspond to the order of inputs.
Fixed names of
imodify()functions. These work like
imap()but preserve the type of
.xin the return value.
modify()and variants are now implemented using
[[<-methods. This implementation should be compatible with most vector classes.
.fare now correctly passed through internal
reduce2_impl(), in keeping with the documentation and
pwalk()now preserve class for inputs of
POSIXctand other atomic S3 classes with an appropriate
[[method (#358, @mikmart).
compose()now supports composition with lambdas (@ColinFay, #556)
pmap()crash with empty lists on the Win32 platform (#565).
.raggedargument evaluates correctly to
TRUEby default when
.depth < 0(@cderv, #530)
accumulate_right()now inherit names from their first input (@AshesITR, #446)
attr_getter()no longer uses partial matching. For example, if an
xobject has a
labelsattribute but no
attr_getter("label")(x)will no longer extract the
labelsattribute (#460, @huftis).
flatten_dfc()now aborts if dplyr is not installed. (#454)
imap_dfr()now works with
.idargument is provided (#429)
lmap_at()accept negative values for
.at, ignoring elements at those positions.
modify()now work with calls and pairlists (#412).
modify_at()now preserve the class of atomic vectors instead of promoting them to lists. New S3 methods are provided for character, logical, double, and integer classes (@t-kalinowski, #417).
list_merge()now handle duplicate duplicate argument names correctly (#441, @mgirlich).
pmap_rawadded to support raw vectors. (#455, @romainfrancois)
NAonly after it has checked all other predicates are either
array_tree()now retain the
dimnames()of the input array (#584, @flying-sheep)
- This is a maintenance release following the release of dplyr 0.7.5.
- Fixes for R 3.1.
We noticed the following issues during reverse dependencies checks:
reduce()fails with this message:
Error: `.x` is empty, and no `.init` supplied, this is because
.xis empty. Fix the problem by supplying an appropriate argument to
.init, or by providing special behaviour when
.xhas length 0.
The type predicates have been migrated to rlang. Consequently the
bare-type-predicatesdocumentation topic is no longer in purrr, which might cause a warning if you cross-reference it.
purrr no longer depends on lazyeval or Rcpp (or dplyr, as of the previous version). This makes the dependency graph of the tidyverse simpler, and makes purrr more suitable as a dependency of lower-level packages.
There have also been two changes to eliminate name conflicts between purrr and dplyr:
split_by()have been removed.
dplyr::order_by()and the complete family doesn't feel that useful. Use tibbles instead (#217).
contains()has been renamed to
has_element()to avoid conflicts with dplyr (#217).
The plucking mechanism used for indexing into data structures with
map() has been extracted into the function
pluck(). Plucking is
often more readable to extract an element buried in a deep data
structure. Compare this syntax-heavy extraction which reads
to the equivalent pluck:
x %>% pluck(1, accessor, "foo")
as_mapper()because it is a tranformation that makes sense primarily for mapping functions, not in general (#298).
.nullhas been renamed to
.defaultto better reflect its intent (#298).
.defaultis returned whenever an element is absent or empty (#231, #254).
as_mapper()sanitises primitive functions by transforming them to closures with standardised argument names (using
rlang::as_closure()). For instance
+is transformed to
function(.x, .y) .x + .y. This results in proper argument matching so that
, .x = 5))produces
list(5 - 1, 5 - 2, ...).
Recursive indexing can now extract objects out of environments (#213) and S4 objects (#200), as well as lists.
attr_getter()makes it possible to extract from attributes like
map(list(iris, mtcars), attr_getter("row.names")).
The argument list for formula-functions has been tweaked so that you can refer to arguments by position with
..2, and so on. This makes it possible to use the formula shorthand for functions with more than two arguments (#289).
safely()and friends no longer capture interrupts: this means that you can now terminate a mapper using one of these with Escape or Ctrl + C (#314)
All map functions now treat
NULLthe same way as an empty vector (#199), and return an empty vector if any input is an empty vector.
map()functions now force their arguments in the same way that base R does for
lapply()(#191). This makes
map()etc easier to use when generating functions.
A new family of "indexed" map functions,
imap_lgl()etc, provide a short-hand for
The data frame suffix
_dfhas been (soft) deprecated in favour of
_dfrto more clearly indicate that it's a row-bind. All variants now also have a
_dfcfor column binding (#167). (These will not be terribly useful until
dplyr::bind_cols()have better semantics for vectors.)
modify() family returns the same output of the type as the
.x. This is in contrast to the
map() family which always
returns a list, regardless of the input type.
The modify functions are S3 generics. However their default methods
should be sufficient for most classes since they rely on the semantics
modify.default() is thus a shorthand for
x <- map(x, f).
at_depth()has been renamed to
.raggedargument, and negative depths are now computed relative to the deepest component of the list (#236).
auto_browse(f)returns a new function that automatically calls
fthrows an error (#281).
vec_depth()computes the depth (i.e. the number of levels of indexing) or a vector (#243).
reduce2_right()make it possible to reduce with a 3 argument function where the first argument is the accumulated value, the second argument is
.x, and the third argument is
stats::modifyList()to replace by position if the list is not named.(#201).
list_merge()operates similarly to
list_modify()but combines instead of replacing (#322).
The legacy function
update_list()is basically a version of
list_modifythat evaluates formulas within the list. It is likely to be deprecated in the future in favour of a tidyeval interface such as a list method for
Minor improvements and bug fixes
Thanks to @dchiu911, the unit test coverage of purrr is now much greater.
All predicate functions are re-exported from rlang (#124).
compact()now works with standard mapper conventions (#282).
cross_n()has been renamed to
_nsuffix was removed for consistency with
map_n()at the start of the project) and
cross_d()has been renamed to
cross_df()for consistency with
NAif present in the input (#174).
invoke()uses a more robust approach to generate the argument list (#249) It no longer uses lazyeval to figure out which enviroment a character
is_scalar_numeric()are deprecated because they don't test for what you might expect at first sight.
reduce()now throws an error if
.xis empty and
.initis not supplied.
zip_n()have been removed.
pmap()coerces data frames to lists to avoid the expensive
[.data.framewhich provides security that is unneeded here (#220).
rdunif()checks its inputs for validity (#211).
set_names()can now take a function to tranform the names programmatically (#276), and you can supply names in
...to reduce typing even more more (#316).
set_names()is now powered by
safely()now actually uses the
transpose()now matches by name if available (#164). You can override the default choice with the new
The function argument of
detect_index()have been renamed from
.f. This is because they have mapper semantics rather than predicate semantics.
This is a compatibility release with dplyr 0.6.0.
- All data-frame based mappers have been removed in favour of new
functions and idioms in the tidyverse.
unslice()have been moved to purrrlyr. This is a bit of an aggresive change but it allows us to make the dependencies much lighter.
Fix for dev tibble support.
as_function()now supports list arguments which allow recursive indexing using either names or positions. They now always stop when encountering the first NULL (#173).
reducecorrectly pass extra arguments to the worker function.
.nullargument that for character and numeric values allows you to specify what to return for null/absent elements (#110). This can be used with any map function, e.g.
map_int(x, 1, .null = NA)
as_function()is now generic.
TRUEonly for regular functions.
Fix crash on GCC triggered by
There are two handy infix functions:
x %||% yis shorthand for
if (is.null(x)) y else x(#109).
x %@% "a"is shorthand for
attr(x, "a", exact = TRUE)(#69).
accumulate()has been added to handle recursive folding. It is shortand for
Reduce(f, .x, accumulate = TRUE)and follows a similar syntax to
reduce()(#145). A right-hand version
accumulate_right()was also added.
map_df()row-binds output together. It's the equivalent of
flatten()is now type-stable and always returns a list. To return a simpler vector, use
invoke()has been overhauled to be more useful: it now works similarly to
.xis NULL, and hence
map_call()has been deprecated.
invoke_map()is a vectorised complement to
invoke()(#125), and comes with typed variants
zip_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
.simplifyargument; instead use the new
possibly()are experimental functions for working with functions with side-effects (e.g. printed output, messages, warnings, and errors) (#120).
safely()is a version of
try()that modifies a function (rather than an expression), and always returns a list with two components,
rep_along()generalise the idea of
is_null()is the snake-case version of
pmap()(parallel map) replaces
map_n()(#132), and has typed-variants suffixed
set_names()is a snake-case alternative to
setNames()with stricter equality checking, and more convenient defaults for pipes:
x %>% set_names()is equivalent to
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 to
dmap(). The latter supports sliced data frames as a shortcut for the combination of
x %>% by_slice(dmap, fun, .collate = "rows"). The conditional variants
dmap_if()also support sliced data frames and will recycle scalar results to the slice size.
map_rows()has been renamed to
invoke_rows(). As other rows-based functionals, it collates results inside lists by default, but with column collation this function is equivalent to
The rows-based functionals gain a
.tooption to name the output column as well as a
.collateargument. 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 called
map*()now use custom C code, rather than relying on
mapply()etc. The performance characteristcs are very similar, but it allows us greater control over the output (#118).
map_lgl()now has second argument
map()followed by the appropriate
map3(x, y, z)->
map_n(list(x, y, z));
walk3(x, y, z) ->pwalk(list(x, y, z))`