Skip to content

Commit

Permalink
Merge pull request #577 from r-lib/f-575-advice
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr authored Aug 18, 2022
2 parents b356b72 + f40f64b commit 5a5619d
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 143 deletions.
6 changes: 6 additions & 0 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ pillar_options <- list2(
superdigit_sep = make_option_impl(
getOption("pillar.superdigit_sep", default = superdigit_sep_default())
),
#' - `advice`: Should advice be displayed in the footer when columns or rows
#' are missing from the output? Defaults to `TRUE` for interactive sessions,
#' and to `FALSE` otherwise.
advice = make_option_impl(
getOption("pillar.advice", default = is_interactive())
),
)

tibble_opt <- function(x, default) {
Expand Down
4 changes: 4 additions & 0 deletions R/tbl-format-footer.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ format_extra_vars <- function(extra_cols, extra_cols_total) {
}

format_footer_advice <- function(x, setup) {
if (!isTRUE(pillar_options$advice())) {
return()
}

if (length(setup$extra_cols) > 0) {
cols <- "`colnames()` to see all variable names"
} else {
Expand Down
3 changes: 3 additions & 0 deletions man/pillar_options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions tests/testthat/_snaps/ansi/ctl_colonnade.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@
# ... 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 @@ -229,7 +228,6 @@
# 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 @@ -247,7 +245,6 @@
# 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 @@ -288,7 +285,6 @@
# 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 @@ -307,7 +303,6 @@
# 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 @@ -348,7 +343,6 @@
# 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 @@ -367,7 +361,6 @@
# 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 @@ -394,7 +387,6 @@
# ... 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 @@ -412,7 +404,6 @@
# 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 @@ -430,5 +421,4 @@
# 1
# more
# variable: ...
# i Use `colnames()` to see all variable names

37 changes: 25 additions & 12 deletions tests/testthat/_snaps/tbl-format-footer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<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 @@ -18,7 +17,6 @@
# 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 @@ -31,7 +29,6 @@
# 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 @@ -47,7 +44,6 @@
# 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 @@ -61,7 +57,6 @@
# 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 @@ -73,7 +68,6 @@
# 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 @@ -85,23 +79,20 @@
# 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 @@ -110,7 +101,6 @@
# ... 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 @@ -121,7 +111,6 @@
# 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 @@ -139,7 +128,6 @@
# 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 @@ -172,5 +160,30 @@
# 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

# pillar.advice option (#575)

Code
tbl_format_footer(tbl_format_setup(new_tbl(as.list(set_names(letters))), width = 80))
Output
<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

# advice when interactive (#575)

Code
tbl_format_footer(tbl_format_setup(new_tbl(as.list(set_names(letters))), width = 80))
Output
<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(list(a = 1:30)), width = 80))
Output
<tbl_format_footer(setup)>
# ... with 20 more rows
# i Use `print(n = ...)` to see more rows

Loading

0 comments on commit 5a5619d

Please sign in to comment.