Skip to content

Commit

Permalink
Explicit error message
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Aug 15, 2024
1 parent d9584df commit 370cd49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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(
template <- reduce(indexes, vec_set_union),
vctrs_error_ptype2 = function(e) {
cli::cli_abort(
"Can't combine named and unnamed vectors.",
arg = template
)
}
)
}

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.

0 comments on commit 370cd49

Please sign in to comment.