Skip to content
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

Merged
merged 8 commits into from
Feb 3, 2021
Merged

Export new generic size_sum() #239

merged 8 commits into from
Feb 3, 2021

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Jan 28, 2021

Closes #173.

Copy link
Member

@DavisVaughan DavisVaughan left a 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]

tests/testthat/test-format_list_of.R Show resolved Hide resolved
tests/testthat/test-obj-sum.R Show resolved Hide resolved
@DavisVaughan
Copy link
Member

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)

@krlmlr
Copy link
Member Author

krlmlr commented Jan 29, 2021

Should we use a placeholder in pillar_shaft.vctrs_list_of() if the size is empty?

@krlmlr
Copy link
Member Author

krlmlr commented Jan 29, 2021

Maybe size_sum() should be responsible only for the inner contents, and pillar still provides the brackets? (Or only adds brackets in the list-of case if it's empty?)

@krlmlr krlmlr merged commit 5368405 into master Feb 3, 2021
@krlmlr krlmlr deleted the f-173-size-sum branch February 3, 2021 17:51
@krlmlr krlmlr mentioned this pull request Feb 3, 2021
krlmlr added a commit that referenced this pull request Feb 20, 2021
- New `size_sum()` generic (#239).

Cherry-pick of 5368405.
krlmlr added a commit that referenced this pull request Feb 20, 2021
- New `size_sum()` generic (#239).

Cherry-pick of 5368405.
krlmlr added a commit that referenced this pull request Feb 24, 2021
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).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pillar_shaft.vctrs_list_of() has no customization point
2 participants