Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export(future_imap_dfc)
export(future_imap_dfr)
export(future_imap_int)
export(future_imap_lgl)
export(future_imap_vec)
export(future_invoke_map)
export(future_invoke_map_chr)
export(future_invoke_map_dbl)
Expand All @@ -41,6 +42,7 @@ export(future_map2_dfc)
export(future_map2_dfr)
export(future_map2_int)
export(future_map2_lgl)
export(future_map2_vec)
export(future_map_at)
export(future_map_chr)
export(future_map_dbl)
Expand All @@ -49,6 +51,7 @@ export(future_map_dfr)
export(future_map_if)
export(future_map_int)
export(future_map_lgl)
export(future_map_vec)
export(future_modify)
export(future_modify_at)
export(future_modify_if)
Expand All @@ -59,6 +62,7 @@ export(future_pmap_dfc)
export(future_pmap_dfr)
export(future_pmap_int)
export(future_pmap_lgl)
export(future_pmap_vec)
export(future_pwalk)
export(future_walk)
export(future_walk2)
Expand Down
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 / Fixes

* New `future_map_vec()`, `future_map2_vec()`, `future_pmap_vec()`, and
`future_imap_vec()` to align with purrr (#261).

* furrr now looks up the purrr mapping function on the worker itself, rather
than sending over its own copy of the function. This avoids possible issues
when you have, say, purrr 1.0.0 locally but purrr 0.3.5 on the worker, where
Expand Down
23 changes: 23 additions & 0 deletions R/future-imap.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ future_imap_lgl <- function(
)
}

#' @rdname future_imap
#' @export
future_imap_vec <- function(
.x,
.f,
...,
.ptype = NULL,
.options = furrr_options(),
.env_globals = parent.frame(),
.progress = FALSE
) {
future_map2_vec(
.x = .x,
.y = vec_index(.x),
.f = .f,
...,
.ptype = .ptype,
.options = .options,
.env_globals = .env_globals,
.progress = .progress
)
}

#' @rdname future_imap
#' @export
future_imap_dfr <- function(
Expand Down
32 changes: 32 additions & 0 deletions R/future-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
#' [progressr](https://CRAN.R-project.org/package=progressr)
#' package.
#'
#' @param .ptype If `NULL`, the default, the output type is the common type of
#' the elements of the result. Otherwise, supply a "prototype" giving the
#' desired type of output.
#'
#' @return All functions return a vector the same length as `.x`.
#'
#' - [future_map()] returns a list
Expand Down Expand Up @@ -211,6 +215,34 @@ future_map_lgl <- function(
)
}

#' @rdname future_map
#' @export
future_map_vec <- function(
.x,
.f,
...,
.ptype = NULL,
.options = furrr_options(),
.env_globals = parent.frame(),
.progress = FALSE
) {
out <- future_map(
.x = .x,
.f = .f,
...,
.options = .options,
.env_globals = .env_globals,
.progress = .progress
)

simplify_impl(
out,
ptype = .ptype,
error_arg = "<output>",
error_call = current_env()
)
}

#' @rdname future_map
#' @export
future_map_dfr <- function(
Expand Down
30 changes: 30 additions & 0 deletions R/future-map2.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,36 @@ future_map2_lgl <- function(
)
}

#' @rdname future_map2
#' @export
future_map2_vec <- function(
.x,
.y,
.f,
...,
.ptype = NULL,
.options = furrr_options(),
.env_globals = parent.frame(),
.progress = FALSE
) {
out <- future_map2(
.x = .x,
.y = .y,
.f = .f,
...,
.options = .options,
.env_globals = .env_globals,
.progress = .progress
)

simplify_impl(
out,
ptype = .ptype,
error_arg = "<output>",
error_call = current_env()
)
}

#' @rdname future_map2
#' @export
future_map2_dfr <- function(
Expand Down
28 changes: 28 additions & 0 deletions R/future-pmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ future_pmap_lgl <- function(
)
}

#' @rdname future_map2
#' @export
future_pmap_vec <- function(
.l,
.f,
...,
.ptype = NULL,
.options = furrr_options(),
.env_globals = parent.frame(),
.progress = FALSE
) {
out <- future_pmap(
.l = .l,
.f = .f,
...,
.options = .options,
.env_globals = .env_globals,
.progress = .progress
)

simplify_impl(
out,
ptype = .ptype,
error_arg = "<output>",
error_call = current_env()
)
}

#' @rdname future_map2
#' @export
future_pmap_dfr <- function(
Expand Down
24 changes: 24 additions & 0 deletions R/utils-purrr.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,28 @@ at_selection <- function(nm, .at) {
.at
}

# `purrr:::simplify_impl()`, but simplified (ha!) by removing `strict`,
# since we are always `strict`
simplify_impl <- function(x, ptype, error_arg, error_call) {
vctrs::obj_check_list(x, arg = error_arg, call = error_call)
vctrs::list_check_all_vectors(x, arg = error_arg, call = error_call)
vctrs::list_check_all_size(x, 1L, arg = error_arg, call = error_call)

names <- vctrs::vec_names(x)
x <- vctrs::vec_set_names(x, NULL)

out <- vctrs::vec_c(
!!!x,
.ptype = ptype,
.error_arg = error_arg,
.error_call = error_call
)

if (!is.null(out)) {
out <- vctrs::vec_set_names(out, names)
}

out
}

# nocov end
15 changes: 15 additions & 0 deletions man/future_imap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions man/future_map.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions man/future_map2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading