Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: list_transpose() takes into account all elements for the template #1136

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions R/list-transpose.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ list_transpose <- function(x,
if (length(x) == 0) {
template <- integer()
} else if (is.null(template)) {
template <- reduce(
map(x, vec_index),
vec_set_union,
error_call = caller_env()
indexes <- map(x, vec_index)
try_fetch(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withCallingHandlers should be adequate here.

template <- reduce(indexes, vec_set_union),
vctrs_error_ptype2 = function(e) {
cli::cli_abort(
"Can't combine named and unnamed vectors.",
arg = template
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs call still?

)
}
)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/list-transpose.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@
Code
list_transpose(list(x = list(a = 1, b = 2), y = list(3, 4)))
Condition
Error:
! Can't combine `x` <character> and `y` <integer>.
Error in `handlers[[1L]]()`:
! Can't combine named and unnamed vectors.

Loading