From dca8b2b892f61bbfe926b88bd09d8c808f6966e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20L=C3=B3pez=20G=C3=BCell?= <99121045+KimLopezGuell@users.noreply.github.com> Date: Thu, 15 Aug 2024 21:37:10 +0100 Subject: [PATCH] allow list_transpose() to work on data frames --- R/list-transpose.R | 8 +++++++- tests/testthat/_snaps/list-transpose.md | 2 +- tests/testthat/test-list-transpose.R | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/R/list-transpose.R b/R/list-transpose.R index 136d60c3..9e76f033 100644 --- a/R/list-transpose.R +++ b/R/list-transpose.R @@ -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) { diff --git a/tests/testthat/_snaps/list-transpose.md b/tests/testthat/_snaps/list-transpose.md index 7b5ab4a1..df1f84a8 100644 --- a/tests/testthat/_snaps/list-transpose.md +++ b/tests/testthat/_snaps/list-transpose.md @@ -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 diff --git a/tests/testthat/test-list-transpose.R b/tests/testthat/test-list-transpose.R index 272c8a49..724fbab7 100644 --- a/tests/testthat/test-list-transpose.R +++ b/tests/testthat/test-list-transpose.R @@ -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) + ) +})