Skip to content

Commit

Permalink
Improve the performance of as_mapper()
Browse files Browse the repository at this point in the history
Fixes #820
  • Loading branch information
hadley committed Aug 27, 2022
1 parent a5dddf1 commit 9319174
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

## Features and fixes

* `as_mapper()` is now around twice as fast when used with character,
integer, or list (#820).

* `map2()` and `pmap()` now recycle names of their first input if
needed (#783).

Expand Down
3 changes: 2 additions & 1 deletion R/as_mapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ find_extract_default <- function(.null, .default) {

plucker <- function(i, default) {
x <- NULL # supress global variables check NOTE
i <- as.list(i)

new_function(
exprs(x = , ... = ),
expr(pluck(x, !!!i, .default = !!default)),
expr(pluck_raw(x, !!i, .default = !!default)),
env = caller_env()
)
}
Expand Down
7 changes: 6 additions & 1 deletion R/pluck.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,19 @@
#' pluck(x, !!!idx)
#' @export
pluck <- function(.x, ..., .default = NULL) {
pluck_raw(.x, list2(...), .default = .default)
}

pluck_raw <- function(.x, index, .default = NULL) {
.Call(
pluck_impl,
x = .x,
index = list2(...),
index = index,
missing = .default,
strict = FALSE
)
}

#' @rdname pluck
#' @export
chuck <- function(.x, ...) {
Expand Down

0 comments on commit 9319174

Please sign in to comment.