-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes: - Introduces a pmap_qto to compliment the map_qto function introduced by @elipousson - map_qto should be slightly more performant (function building is done outside the map call) - collapse and sep are now passed to .type functions where relevant
- Loading branch information
Showing
7 changed files
with
409 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# nocov start | ||
|
||
#' all functions here are copied from the | ||
#' `standalone-purrr.R` script in rlang: | ||
#' https://github.com/r-lib/rlang/blob/main/R/standalone-purrr.R | ||
#' @noRd | ||
map <- function(.x, .f, ...) { | ||
.f <- as_function(.f, env = global_env()) | ||
lapply(.x, .f, ...) | ||
} | ||
|
||
#' @noRd | ||
map_chr <- function(.x, .f, ...) { | ||
.rlang_purrr_map_mold(.x, .f, character(1L), ...) | ||
} | ||
|
||
#' @noRd | ||
map_int <- function(.x, .f, ...) { | ||
.rlang_purrr_map_mold(.x, .f, integer(1), ...) | ||
} | ||
|
||
#' @noRd | ||
.rlang_purrr_map_mold <- function(.x, .f, .mold, ...) { | ||
.f <- as_function(.f, env = global_env()) | ||
out <- vapply(.x, .f, .mold, ..., USE.NAMES = FALSE) | ||
names(out) <- names(.x) | ||
out | ||
} | ||
|
||
#' @noRd | ||
pmap <- function(.l, .f, ...) { | ||
.f <- as.function(.f) | ||
args <- .rlang_purrr_args_recycle(.l) | ||
do.call("mapply", c( | ||
FUN = list(quote(.f)), | ||
args, MoreArgs = quote(list(...)), | ||
SIMPLIFY = FALSE, USE.NAMES = FALSE | ||
)) | ||
} | ||
|
||
#' @noRd | ||
.rlang_purrr_args_recycle <- function(args) { | ||
lengths <- map_int(args, length) | ||
n <- max(lengths) | ||
|
||
stopifnot(all(lengths == 1L | lengths == n)) | ||
to_recycle <- lengths == 1L | ||
args[to_recycle] <- map(args[to_recycle], function(x) rep.int(x, n)) | ||
|
||
args | ||
} | ||
|
||
# nocov end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.