Skip to content
Open
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
Expand Up @@ -22,6 +22,8 @@

* `map()`, `map2()`, and `pmap()` now automatically set the correct environment so that `format` strings to access to local variables (@jcolt45, #1078).

* `map_vec()` no longer fails on empty named lists (#1206).

# purrr 1.1.0

* purrr now requires R >= 4.1, so we can rely on the base pipe and lambda
Expand Down
5 changes: 4 additions & 1 deletion R/list-simplify.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,8 @@ simplify_impl <- function(
}
}
)
vec_set_names(out, names)
if (!is.null(out)) {
out <- vec_set_names(out, names)
}
out
}
5 changes: 5 additions & 0 deletions tests/testthat/test-list-simplify.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ test_that("only uses outer names", {
expect_named(out, c("a", "", "c"))
})

test_that("empty lists simplify to NULL", {
expect_equal(list_simplify(list()), NULL)
expect_equal(list_simplify(set_names(list())), NULL)
})

test_that("ptype is enforced", {
expect_equal(list_simplify(list(1, 2), ptype = double()), c(1, 2))
expect_snapshot(list_simplify(list(1, 2), ptype = character()), error = TRUE)
Expand Down