-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
584bca9
commit 45499b1
Showing
2 changed files
with
27 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
test_that("compact_list works as expected", { | ||
expect_equal(compact_list(list(NULL, 1, c(NA, NA))), list(1, c(NA, NA))) | ||
expect_equal(compact_list(c(1, NA, NA)), c(1, NA, NA)) | ||
expect_equal(compact_list(list(NULL, 1, list(NULL, NULL))), list(1)) | ||
expect_equal(compact_list(c(1, NA, NA), remove_na = TRUE), 1) | ||
expect_equal(compact_list(c(1, 2, 3), remove_na = TRUE), c(1, 2, 3)) | ||
expect_equal(compact_list(""), "") | ||
expect_identical(compact_list(list(NULL, 1, c(NA, NA))), list(1, c(NA, NA))) | ||
expect_identical(compact_list(c(1, NA, NA)), c(1, NA, NA)) | ||
expect_identical(compact_list(list(NULL, 1, list(NULL, NULL))), list(1)) | ||
expect_identical(compact_list(c(1, NA, NA), remove_na = TRUE), 1) | ||
expect_identical(compact_list(c(1, 2, 3), remove_na = TRUE), c(1, 2, 3)) | ||
expect_identical(compact_list(""), "") | ||
expect_null(compact_list(NULL)) | ||
expect_equal(compact_list(logical(0)), logical(0)) | ||
expect_identical(compact_list(logical(0)), logical(0)) | ||
}) | ||
|
||
test_that("compact_list, logical > 1", { | ||
x <- list(a = 1, b = c(1, 2), c = NA) | ||
expect_equal(compact_list(x, remove_na = TRUE), list(a = 1, b = c(1, 2))) | ||
expect_equal(compact_list(x, remove_na = FALSE), list(a = 1, b = c(1, 2), c = NA)) | ||
expect_identical(compact_list(x, remove_na = TRUE), list(a = 1, b = c(1, 2))) | ||
expect_identical(compact_list(x, remove_na = FALSE), list(a = 1, b = c(1, 2), c = NA)) | ||
x <- list(a = 1, b = c(NA, NA), c = NA) | ||
expect_equal(compact_list(x, remove_na = TRUE), list(a = 1)) | ||
expect_equal(compact_list(x, remove_na = FALSE), list(a = 1, b = c(NA, NA), c = NA)) | ||
expect_identical(compact_list(x, remove_na = TRUE), list(a = 1)) | ||
expect_identical(compact_list(x, remove_na = FALSE), list(a = 1, b = c(NA, NA), c = NA)) | ||
}) | ||
|
||
test_that("compact_list, vctrs", { | ||
data(mtcars) | ||
class(mtcars$mpg) <- c("haven_labelled", "vctrs_vctr", "double") | ||
attr(mtcars$mpg, "labels") <- c(`21` = 21) | ||
out <- compact_list(mtcars) | ||
expect_true(all(vapply(out, class, character(1)) == "numeric")) | ||
}) |
45499b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is an acceptable solution. The returned object needs to retain the vctrs classes.
45499b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that packages should not interfere with R language to such an extent that standard R code no longer works. ;-)
From some point of view, there's more benefit than harm when that class is removed, because it increases the probability that the returned objects works better with R / other packages than before, because it doesn't break regular R code.
But yes, if we find a solution to avoid my "hack", let's go that route.