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

feat: Offer advice on how to print everything #567

Merged
merged 4 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions R/tbl-format-footer.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,25 @@ format_extra_vars <- function(extra_cols, extra_cols_total) {
}

format_footer_advice <- function(x, setup) {
paste0(symbol$info, " Use more")
NULL
if (length(setup$extra_cols) > 0) {
cols <- "`colnames()` to see all variable names"
} else {
cols <- NULL
}

if (is.na(setup$rows_missing) || setup$rows_missing > 0) {
rows <- "`print(n = ...)` to see more rows"
} else {
rows <- NULL
}

advice <- enum_collapse(c(rows, cols))

if (length(advice) == 0) {
return()
}

paste0(symbol$info, " Use ", paste(advice, collapse = " "))
}

wrap_footer <- function(footer, setup, lines = setup$max_footer_lines, ellipsis = TRUE) {
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/_snaps/ansi/ctl_colonnade.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
# ... with 1 more
# variable:
# a$y <dbl>
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x, width = 15, focus = "b")
Output
Expand All @@ -228,6 +229,7 @@
# more
# variable:
# a <tbl[,2]>
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x, width = 10, focus = "b")
Output
Expand All @@ -245,6 +247,7 @@
# 1
# more
# variable: ...
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x[2:1], width = 30, focus = "a")
Output
Expand Down Expand Up @@ -285,6 +288,7 @@
# more
# variable:
# b <chr>
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x[2:1], width = 10, focus = "a")
Output
Expand All @@ -303,6 +307,7 @@
# more
# variables:
# a$y <dbl>, ...
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x, width = 30, focus = c("a", "b"))
Output
Expand Down Expand Up @@ -343,6 +348,7 @@
# more
# variable:
# a$y <dbl>
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x, width = 10, focus = c("a", "b"))
Output
Expand All @@ -361,6 +367,7 @@
# more
# variables:
# a$y <dbl>, ...
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x[2:1], width = 30, focus = c("a", "b"))
Output
Expand All @@ -387,6 +394,7 @@
# ... with 1 more
# variable:
# a$y <dbl>
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x[2:1], width = 15, focus = c("a", "b"))
Output
Expand All @@ -404,6 +412,7 @@
# more
# variable:
# a$y <dbl>
# i Use `colnames()` to see all variable names
Code
tbl_format_setup(x[2:1], width = 10, focus = c("a", "b"))
Output
Expand All @@ -421,4 +430,5 @@
# 1
# more
# variable: ...
# i Use `colnames()` to see all variable names

13 changes: 13 additions & 0 deletions tests/testthat/_snaps/tbl-format-footer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<tbl_format_footer(setup)>
# ... with 13 more variables: n <chr>, o <chr>, p <chr>, q <chr>, r <chr>,
# s <chr>, t <chr>, u <chr>, v <chr>, w <chr>, x <chr>, y <chr>, z <chr>
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_tbl(as.list(set_names(letters))), width = 30))
Output
Expand All @@ -17,6 +18,7 @@
# k <chr>, l <chr>,
# m <chr>, n <chr>,
# o <chr>, p <chr>, ...
# i Use `colnames()` to see all variable names

# wrapping column names with spaces in the footer

Expand All @@ -29,6 +31,7 @@
# p <chr>, q <chr>, r <chr>, s <chr>, t <chr>, u <chr>, v <chr>,
# w <chr>, x <chr>, y <chr>, z <chr>,
# `a b c d e f g h i j k l m n o p q r s t u v w x y z` <dbl>
# i Use `colnames()` to see all variable names

# overflow

Expand All @@ -44,6 +47,7 @@
# k <chr>, l <chr>, m <chr>, n <chr>, o <chr>, p <chr>, q <chr>,
# r <chr>, s <chr>, t <chr>, u <chr>, v <chr>, w <chr>, x <chr>,
# y <chr>, z <chr>, a <chr>, b <chr>, c <chr>, d <chr>, ...
# i Use `colnames()` to see all variable names

# max_footer_lines option

Expand All @@ -57,6 +61,7 @@
# aq <int>, bq <int>, ar <int>, br <int>, as <int>, bs <int>, at <int>,
# bt <int>, au <int>, bu <int>, av <int>, bv <int>, aw <int>, bw <int>,
# ax <int>, bx <int>, ay <int>, by <int>, az <int>, bz <int>
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl("prefix_")))
Output
Expand All @@ -68,6 +73,7 @@
# prefix_bl <int>, prefix_am <int>, prefix_bm <int>, prefix_an <int>,
# prefix_bn <int>, prefix_ao <int>, prefix_bo <int>, prefix_ap <int>,
# prefix_bp <int>, prefix_aq <int>, prefix_bq <int>, prefix_ar <int>, ...
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl("a_very_long_prefix_")))
Output
Expand All @@ -79,20 +85,23 @@
# a_very_long_prefix_ai <int>, a_very_long_prefix_bi <int>,
# a_very_long_prefix_aj <int>, a_very_long_prefix_bj <int>,
# a_very_long_prefix_ak <int>, a_very_long_prefix_bk <int>, ...
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl(""), max_footer_lines = 3))
Output
<tbl_format_footer(setup)>
# ... with 39 more variables: bg <int>, ah <int>, bh <int>, ai <int>, bi <int>,
# aj <int>, bj <int>, ak <int>, bk <int>, al <int>, bl <int>, am <int>,
# bm <int>, an <int>, bn <int>, ao <int>, bo <int>, ap <int>, bp <int>, ...
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl("prefix_"), max_footer_lines = 3))
Output
<tbl_format_footer(setup)>
# ... with 43 more variables: prefix_be <int>, prefix_af <int>,
# prefix_bf <int>, prefix_ag <int>, prefix_bg <int>, prefix_ah <int>,
# prefix_bh <int>, prefix_ai <int>, prefix_bi <int>, prefix_aj <int>, ...
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl("a_very_long_prefix_"),
max_footer_lines = 3))
Expand All @@ -101,6 +110,7 @@
# ... with 43 more variables: a_very_long_prefix_be <int>,
# a_very_long_prefix_af <int>, a_very_long_prefix_bf <int>,
# a_very_long_prefix_ag <int>, a_very_long_prefix_bg <int>, ...
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl(""), max_footer_lines = Inf))
Output
Expand All @@ -111,6 +121,7 @@
# aq <int>, bq <int>, ar <int>, br <int>, as <int>, bs <int>, at <int>,
# bt <int>, au <int>, bu <int>, av <int>, bv <int>, aw <int>, bw <int>,
# ax <int>, bx <int>, ay <int>, by <int>, az <int>, bz <int>
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl("prefix_"), max_footer_lines = Inf))
Output
Expand All @@ -128,6 +139,7 @@
# prefix_bx <int>, prefix_ay <int>, prefix_by <int>, prefix_az <int>,
# prefix_bz <int>, and abbreviated variable names 1: prefix_bb, 2: prefix_ac,
# 3: prefix_bc, 4: prefix_ad, 5: prefix_bd, 6: prefix_ae
# i Use `colnames()` to see all variable names
Code
tbl_format_footer(tbl_format_setup(new_footer_tbl("a_very_long_prefix_"),
max_footer_lines = Inf))
Expand Down Expand Up @@ -160,4 +172,5 @@
# 5: a_very_long_prefix_ac, 6: a_very_long_prefix_bc,
# 7: a_very_long_prefix_ad, 8: a_very_long_prefix_bd,
# 9: a_very_long_prefix_ae
# i Use `colnames()` to see all variable names

Loading