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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# purrr (development version)

* `as_mapper.default()` optimized by removing special named argument handling for primitive functions (@mtcarsalot, #1088).

* `list_flatten()` gains an `is_node` parameter taking a predicate function that determines whether an input element is a node or a leaf (@salim-b, #1179).

* `in_parallel()` now accepts objects, including helper functions, supplied to `...` for all locally-defined functions (#1208).
Expand Down
13 changes: 1 addition & 12 deletions R/map-mapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,7 @@ as_mapper <- function(.f, ...) {

#' @export
as_mapper.default <- function(.f, ...) {
if (typeof(.f) %in% c("special", "builtin")) {
.f <- rlang::as_closure(.f)

# Workaround until fixed in rlang
if (is_reference(fn_env(.f), base_env())) {
environment(.f) <- global_env()
}

.f
} else {
rlang::as_function(.f)
}
rlang::as_function(.f)
}

#' @export
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-map-mapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("can supply length > 1 vectors", {
# primitive functions --------------------------------------------------

test_that("primitive functions are wrapped", {
expect_identical(as_mapper(`-`)(.y = 10, .x = 5), -5)
expect_identical(as_mapper(`-`)(.y = 10, .x = 5), 5) # positional matching, not by name
expect_identical(as_mapper(`c`)(1, 3, 5), c(1, 3, 5))
})

Expand Down
Loading