Skip to content

Commit

Permalink
allow list_transpose() to work on data frames
Browse files Browse the repository at this point in the history
  • Loading branch information
KimLopezGuell committed Aug 15, 2024
1 parent 49bb36b commit dca8b2b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion R/list-transpose.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ list_transpose <- function(x,
simplify = NA,
ptype = NULL,
default = NULL) {
vec_check_list(x)
if(!is.list(x)) {
cli::cli_abort(
"{.arg x} must be a list, not {.obj_type_friendly {x}}",
arg = x
)
}

check_dots_empty()

if (length(x) == 0) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/list-transpose.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
list_transpose(10)
Condition
Error in `list_transpose()`:
! `x` must be a list, not the number 10.
! `x` must be a list, not a number
Code
list_transpose(list(1), template = mean)
Condition
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-list-transpose.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ test_that("validates inputs", {
list_transpose(list(1), template = mean)
})
})

test_that("works on data frames", {
expect_no_error(
list_transpose(mtcars)
)
})

0 comments on commit dca8b2b

Please sign in to comment.