From 83043e28c77567ae93dae8f4b26eeb9c7de7cb0c Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Wed, 21 Aug 2024 15:59:34 -0400 Subject: [PATCH 1/3] Revert allowing data frames in `list_transpose()` --- R/list-transpose.R | 3 +-- tests/testthat/_snaps/list-transpose.md | 10 +++++++++- tests/testthat/test-list-transpose.R | 9 ++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/R/list-transpose.R b/R/list-transpose.R index a3dba5b2..e085558e 100644 --- a/R/list-transpose.R +++ b/R/list-transpose.R @@ -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) { diff --git a/tests/testthat/_snaps/list-transpose.md b/tests/testthat/_snaps/list-transpose.md index 10ccbc6d..b7853277 100644 --- a/tests/testthat/_snaps/list-transpose.md +++ b/tests/testthat/_snaps/list-transpose.md @@ -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 object. + # integer template requires exact length of list() simplify etc Code @@ -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 diff --git a/tests/testthat/test-list-transpose.R b/tests/testthat/test-list-transpose.R index 872e5b7f..3996f70f 100644 --- a/tests/testthat/test-list-transpose.R +++ b/tests/testthat/test-list-transpose.R @@ -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", { From cda7a5b474dc614dc02bc31d047acb72df22d43a Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Wed, 21 Aug 2024 16:00:35 -0400 Subject: [PATCH 2/3] Tweak NEWS bullet --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 5d5177af..815872cd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # purrr (development version) -* `list_transpose()` now works with data.frames (@KimLopezGuell, #1109). +* Added a test to assert that `list_transpose()` does not work on data frames + (@KimLopezGuell, #1141, #1149). * Added `imap_vec()` (#1084) * `list_transpose()` inspects all elements to determine the correct template if it's not provided by the user (#1128, @krlmlr). From 0fda26d7cb71904fada9b47ccd194496cd32da8f Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Wed, 21 Aug 2024 16:42:01 -0400 Subject: [PATCH 3/3] One liner --- tests/testthat/test-list-transpose.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/testthat/test-list-transpose.R b/tests/testthat/test-list-transpose.R index 3996f70f..56ed28ba 100644 --- a/tests/testthat/test-list-transpose.R +++ b/tests/testthat/test-list-transpose.R @@ -8,9 +8,7 @@ test_that("can't transpose data frames", { df <- data.frame(x = 1:2, y = 4:5) # i.e. be consistent with other `list_*()` functions from purrr/vctrs - expect_snapshot(error = TRUE, { - list_transpose(df) - }) + expect_snapshot(error = TRUE, list_transpose(df)) }) test_that("transposing empty list returns empty list", {