-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix compact_list() for labelled + other vctrs classes #880
base: main
Are you sure you want to change the base?
Conversation
Thanks, however, there are a few failing tests related to this PR:
|
Yeah saw that -- was doing this on a plane and didn't have a chance to investigate the tests before landing |
That's why I don't like tidyverse... breaks standard R code in so many instances, and people are not aware it's a tidyverse problem. |
It's mostly just vctrs that does that because of the strong typing |
I think the easiest thing is just to remove the vctrs-attributes before running the function: |
@strengejacke I'm worried that that will have unforseen consequences. We should adjust the Why exactly are we comparing against the character value "NULL"? Is it just so that lists of all NULLs return true? (ala
If we do need to retain the comparison against character "NULL" for another reason, let's do one of these:
or:
|
I'm not sure which exact situation is caught, I remember we had to do this. Probably when |
Seems like we had similar tries, but reverted: |
Difficult to track, it was even discussed when the functions were in datawizard: easystats/datawizard#52 (comment) |
Use `is.character(i) || …` to head off vctrs-induced type mismatch
Okay, in that case, let's keep the check against character "NULL" and head off the the vctrs type-checking by using |
(I am not in principle opposed to vctrs' strictness around type comparisons; it is better practice than relying on implicit coercion. I agree with tidyverse team that R's ubiquitous type coercion causes more problems than it solves. But I wish that the error messages were more helpful at diagnosing that is the issue.) |
When you look at the commit history of that file, you'll see that we had similar attempts in the past: Not sure why we ended up with the current solution |
@@ -10,9 +10,9 @@ | |||
#' @export | |||
compact_list <- function(x, remove_na = FALSE) { | |||
if (remove_na) { | |||
x[!sapply(x, function(i) !is_model(i) && !inherits(i, c("Formula", "gFormula")) && (length(i) == 0L || is.null(i) || (length(i) == 1L && is.na(i)) || all(is.na(i)) || any(is.character(i) && i == "NULL", na.rm = TRUE)))] | |||
x[!sapply(x, function(i) !is_model(i) && !inherits(i, c("Formula", "gFormula")) && (length(i) == 0L || is.null(i) || (length(i) == 1L && is.na(i)) || all(is.na(i)) || all(sapply(i, is.null)) || any(sapply(i, \(j) length(j) == 1 && is.character(j) && j == "NULL"), na.rm = TRUE)))] |
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.
We shouldn't use lambdas here due to backwards compatibility.
Neither your approach nor mine work correctly. See this result, either for this PR, or #881: out <- lapply(
mtcars[, 1:3, drop = FALSE],
bayestestR::ci,
ci = c(0.9, 0.8),
verbose = FALSE
)
insight::compact_list(out)
#> named list() Expected result out <- lapply(
mtcars[, 1:3, drop = FALSE],
bayestestR::ci,
ci = c(0.9, 0.8),
verbose = FALSE
)
insight::compact_list(out)
#> $mpg
#> Equal-Tailed Interval
#>
#> 90% ETI | 80% ETI
#> -------------------------------
#> [12.00, 31.30] | [14.34, 30.09]
#>
#> $cyl
#> Equal-Tailed Interval
#>
#> 90% ETI | 80% ETI
#> ---------------------------
#> [4.00, 8.00] | [4.00, 8.00]
#>
#> $disp
#> Equal-Tailed Interval
#>
#> 90% ETI | 80% ETI
#> ---------------------------------
#> [77.35, 449.00] | [80.61, 396.00] |
Closes easystats/performance#727