co-analysis / a11ytables

R package: generate best-practice stats spreadsheets for publication
https://co-analysis.github.io/a11ytables/
Other
42 stars 3 forks source link

Consider tibble printing, conditional on whether {tibble} is attached #26

Closed matt-dray closed 2 years ago

matt-dray commented 2 years ago

As it stands, a11ytable-class objects are data.frames. It would be nice to view them as tibbles if the user has {tibble} installed/loaded. {a11ytables} seeks to be low-dependency—besides {openxlsx}—so doesn't import the tidyverse.

See this PR to {palmerpenguins} for how this could be done.

Might reduce the need for writing a specific print method (#23)?

TimTaylor commented 2 years ago

See https://github.com/co-analysis/a11ytables/issues/23#issuecomment-1040770622. Given how much nicer it looks I'd consider using {pillar} directly and just taking at as an import. If you did need to lighten dependencies at a later date you then only need to focus on printing and formatting.

TimTaylor commented 2 years ago

Setting the class as c("a11ytable", "tbl", "data.frame") then, once you've added {pillar} as an import the only extra code you would need is something like

#' @importFrom pillar tbl_sum
NULL

#' @export
tbl_sum.a11ytables <- function(x, ...) {
    header <- sprintf(
        "%s x %s",
        formatC(nrow(x), big.mark = ","),
        formatC(ncol(x), big.mark = ",")
    )
    c("a11ytables" = header)
}
matt-dray commented 2 years ago

@TimTaylor This approach is now in the package and I've added you as a contributor. PR for any changes you want to your details in the DESCRIPTION.