diff --git a/R/list-transpose.R b/R/list-transpose.R index 390101cb..5abcbaec 100644 --- a/R/list-transpose.R +++ b/R/list-transpose.R @@ -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 + ) + } ) } diff --git a/tests/testthat/_snaps/list-transpose.md b/tests/testthat/_snaps/list-transpose.md index 92809b55..31d33924 100644 --- a/tests/testthat/_snaps/list-transpose.md +++ b/tests/testthat/_snaps/list-transpose.md @@ -69,6 +69,6 @@ Code list_transpose(list(x = list(a = 1, b = 2), y = list(3, 4))) Condition - Error: - ! Can't combine `x` and `y` . + Error in `handlers[[1L]]()`: + ! Can't combine named and unnamed vectors.