-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export new generic size_sum() #239
Conversation
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 this looks good! Here is an example of how I could use this to solve #173, using either a list or a list-of. I think my suggested tests to add would catch both of these cases
library(pillar)
library(tibble)
library(vctrs)
tbl1 <- new_tibble(
list(
type = c("warning", "error"),
message = c("foo", "bar")
),
nrow = 2L,
class = "tbl_notes"
)
tbl2 <- new_tibble(
list(
type = c("warning", "error", "error"),
message = c("foo", "bar", "baz")
),
nrow = 3L,
class = "tbl_notes"
)
vec_ptype_abbr.tbl_notes <- function(x, ...) {
"tbl-notes"
}
type_sum.tbl_notes <- function(x) {
"tbl-notes"
}
size_sum.tbl_notes <- function(x) {
w <- sum(x$type == "warning")
e <- sum(x$type == "error")
paste0("[", w, " W / ", e, " E]")
}
col1 <- list(tbl1, tbl2)
col2 <- list_of(tbl1, tbl2)
tibble(col1 = col1, col2 = col2)
#> # A tibble: 2 x 2
#> col1 col2
#> <list> <list<tbl-notes>>
#> 1 <tbl-notes [1 W / 1 E]> [1 W / 1 E]
#> 2 <tbl-notes [1 W / 2 E]> [1 W / 2 E]
Potential issue when there is no size and you put it in a list-of library(pillar)
library(tibble)
library(vctrs)
x <- structure(1, class = "foo")
lst <- list_of(x, x)
size_sum.foo <- function(x) {
""
}
tibble(lst = lst)
#> # A tibble: 2 x 1
#> lst
#> <list<foo>>
#> 1
#> 2 Created on 2021-01-28 by the reprex package (v0.3.0.9001) |
Should we use a placeholder in |
Maybe |
pillar 1.5.0 - `obj_sum()` now always returns a string. `pillar_shaft.list()` iterates over its elements and calls `obj_sum()` for each (#137). - Breaking: `print.pillar()` and `print.pillar_ornament()` now show `<pillar>` `<pillar_ornament>` in the first line (#227, #228). - pillar has been re-licensed as MIT (#215). - New `size_sum()` generic (#239). - New `ctl_new_pillar()` and `ctl_new_compound_pillar()` used via `print.tbl()`, `format.tbl()` and `tbl_format_setup.tbl()` (#230). - New `new_pillar()` low-level constructor (#230). - New `new_pillar_component()` and `pillar_component()` (#230). - New articles `vignette("extending")` and `vignette("printing")` (#251). - All printing code has been moved from tibble to pillar (#179), including `glimpse()` (#234). This concentrates the printing code in one package and allows for better extensibility. - Improve formatting for `"Surv"` and `"Surv2"` classes from the survival package (#199). - Vectors of the `vctrs_unspecified()` class are formatted better (#256). - Arrays are now formatted by showing only their first slice (#142). - Avoid wrapping extra column names with spaces (#254). - Now using debugme to simplify understand the complex control flow, see `vignette("debugme")` (#248). - New `format.pillar_ornament()` (#228). - Using testthat 3e (#218). - Avoid pillar.bold option in most tests (#216). - Change internal storage format for `colonnade()` and `extra_cols()` (#204).
Closes #173.