Skip to content

Commit

Permalink
Revert allowing data frames in list_transpose()
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Aug 21, 2024
1 parent 213c12e commit 83043e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions R/list-transpose.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ list_transpose <- function(x,
simplify = NA,
ptype = NULL,
default = NULL) {

check_list(x)
obj_check_list(x)
check_dots_empty()

if (length(x) == 0) {
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/_snaps/list-transpose.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# can't transpose data frames

Code
list_transpose(df)
Condition
Error in `list_transpose()`:
! `x` must be a list, not a <data.frame> object.

# integer template requires exact length of list() simplify etc

Code
Expand Down Expand Up @@ -57,7 +65,7 @@
list_transpose(10)
Condition
Error in `list_transpose()`:
! `x` must be a list, not a number.
! `x` must be a list, not the number 10.
Code
list_transpose(list(1), template = mean)
Condition
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-list-transpose.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ test_that("can transpose homogenous list", {
expect_equal(out, list(a = c(x = 1, y = 3), b = c(x = 2, y = 4)))
})

test_that("can transpose data frames", {
test_that("can't transpose data frames", {
df <- data.frame(x = 1:2, y = 4:5)
out <- list_transpose(df)
expect_equal(out, list(c(x = 1, y = 4), c(x = 2, y = 5)))

# i.e. be consistent with other `list_*()` functions from purrr/vctrs
expect_snapshot(error = TRUE, {
list_transpose(df)
})
})

test_that("transposing empty list returns empty list", {
Expand Down

0 comments on commit 83043e2

Please sign in to comment.