diff --git a/NEWS.md b/NEWS.md index d2495de0..7ce9e7a8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -30,6 +30,9 @@ ## Features and fixes +* `as_mapper()` is now around twice as fast when used with character, + integer, or list (#820). + * `vec_depth()` is now `pluck_depth()` and works with more types of input (#818). diff --git a/R/as_mapper.R b/R/as_mapper.R index fa7ee804..c37ddab1 100644 --- a/R/as_mapper.R +++ b/R/as_mapper.R @@ -98,11 +98,12 @@ find_extract_default <- function(.null, .default) { plucker <- function(i, default) { x <- NULL # supress global variables check NOTE + i <- as.list(i) + # Use metaprogramming to create function that prints nicely new_function( exprs(x = , ... = ), - expr(pluck(x, !!!i, .default = !!default)), - env = caller_env() + expr(pluck_raw(x, !!i, .default = !!default)) ) } diff --git a/R/pluck.R b/R/pluck.R index 7e2b2403..8304b7f0 100644 --- a/R/pluck.R +++ b/R/pluck.R @@ -122,15 +122,19 @@ #' @export pluck <- function(.x, ..., .default = NULL) { check_dots_unnamed() + 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, ...) {