From 2df8bcfa31f9503dd8e0ba697f43ab9c25f5ebad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 8 Jul 2022 05:03:39 +0200 Subject: [PATCH 1/4] Give advice on column names --- R/tbl-format-footer.R | 5 +- tests/testthat/_snaps/tbl-format-footer.md | 13 +++ tests/testthat/_snaps/tbl-format-setup.md | 80 +++++++++++++++++++ tests/testthat/_snaps/tbl-format.md | 4 + .../testthat/_snaps/unicode/ctl_colonnade.md | 10 +++ 5 files changed, 110 insertions(+), 2 deletions(-) diff --git a/R/tbl-format-footer.R b/R/tbl-format-footer.R index d86dba33f..3d7aa6468 100644 --- a/R/tbl-format-footer.R +++ b/R/tbl-format-footer.R @@ -130,8 +130,9 @@ 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) { + paste0(symbol$info, " Use `colnames()` to see all variable names") + } } wrap_footer <- function(footer, setup, lines = setup$max_footer_lines, ellipsis = TRUE) { diff --git a/tests/testthat/_snaps/tbl-format-footer.md b/tests/testthat/_snaps/tbl-format-footer.md index 57abbf79e..746076e50 100644 --- a/tests/testthat/_snaps/tbl-format-footer.md +++ b/tests/testthat/_snaps/tbl-format-footer.md @@ -6,6 +6,7 @@  # ... with 13 more variables: n , o , p , q , r , # s , t , u , v , w , x , y , z  + # 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 @@ -17,6 +18,7 @@ # k , l , # m , n , # o , p , ... + # i Use `colnames()` to see all variable names # wrapping column names with spaces in the footer @@ -29,6 +31,7 @@ # p , q , r , s , t , u , v , # w , x , y , z , # `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` + # i Use `colnames()` to see all variable names # overflow @@ -44,6 +47,7 @@ # k , l , m , n , o , p , q , # r , s , t , u , v , w , x , # y , z , a , b , c , d , ... + # i Use `colnames()` to see all variable names # max_footer_lines option @@ -57,6 +61,7 @@ # aq , bq , ar , br , as , bs , at , # bt , au , bu , av , bv , aw , bw , # ax , bx , ay , by , az , bz + # i Use `colnames()` to see all variable names Code tbl_format_footer(tbl_format_setup(new_footer_tbl("prefix_"))) Output @@ -68,6 +73,7 @@ # prefix_bl , prefix_am , prefix_bm , prefix_an , # prefix_bn , prefix_ao , prefix_bo , prefix_ap , # prefix_bp , prefix_aq , prefix_bq , prefix_ar , ... + # i Use `colnames()` to see all variable names Code tbl_format_footer(tbl_format_setup(new_footer_tbl("a_very_long_prefix_"))) Output @@ -79,6 +85,7 @@ # a_very_long_prefix_ai , a_very_long_prefix_bi , # a_very_long_prefix_aj , a_very_long_prefix_bj , # a_very_long_prefix_ak , a_very_long_prefix_bk , ... + # i Use `colnames()` to see all variable names Code tbl_format_footer(tbl_format_setup(new_footer_tbl(""), max_footer_lines = 3)) Output @@ -86,6 +93,7 @@ # ... with 39 more variables: bg , ah , bh , ai , bi , # aj , bj , ak , bk , al , bl , am , # bm , an , bn , ao , bo , ap , bp , ... + # i Use `colnames()` to see all variable names Code tbl_format_footer(tbl_format_setup(new_footer_tbl("prefix_"), max_footer_lines = 3)) Output @@ -93,6 +101,7 @@ # ... with 43 more variables: prefix_be , prefix_af , # prefix_bf , prefix_ag , prefix_bg , prefix_ah , # prefix_bh , prefix_ai , prefix_bi , prefix_aj , ... + # 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)) @@ -101,6 +110,7 @@ # ... with 43 more variables: a_very_long_prefix_be , # a_very_long_prefix_af , a_very_long_prefix_bf , # a_very_long_prefix_ag , a_very_long_prefix_bg , ... + # i Use `colnames()` to see all variable names Code tbl_format_footer(tbl_format_setup(new_footer_tbl(""), max_footer_lines = Inf)) Output @@ -111,6 +121,7 @@ # aq , bq , ar , br , as , bs , at , # bt , au , bu , av , bv , aw , bw , # ax , bx , ay , by , az , bz + # i Use `colnames()` to see all variable names Code tbl_format_footer(tbl_format_setup(new_footer_tbl("prefix_"), max_footer_lines = Inf)) Output @@ -128,6 +139,7 @@ # prefix_bx , prefix_ay , prefix_by , prefix_az , # prefix_bz , 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)) @@ -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 diff --git a/tests/testthat/_snaps/tbl-format-setup.md b/tests/testthat/_snaps/tbl-format-setup.md index 6e58aaf63..fab384c4d 100644 --- a/tests/testthat/_snaps/tbl-format-setup.md +++ b/tests/testthat/_snaps/tbl-format-setup.md @@ -15,6 +15,7 @@ # with 3 more variables: column_zero_zero , `col 01` , `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 5) Output @@ -34,6 +35,7 @@ # variables: # column_zero_zero , # `col 01` , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 6) Output @@ -53,6 +55,7 @@ # variables: # column_zero_zero , # `col 01` , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 7) Output @@ -72,6 +75,7 @@ # variables: # column_zero_zero , # `col 01` , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 8) Output @@ -90,6 +94,7 @@ # variables: # column_zero_zero , # `col 01` , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 9) Output @@ -112,6 +117,7 @@ # variables: # `col 01` , # `col 05` , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 10) Output @@ -133,6 +139,7 @@ # variables: # `col 01` , # `col 05` , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 11) Output @@ -155,6 +162,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 12) Output @@ -177,6 +185,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 13) Output @@ -199,6 +208,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 14) Output @@ -221,6 +231,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 15) Output @@ -243,6 +254,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 16) Output @@ -264,6 +276,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 17) Output @@ -285,6 +298,7 @@ # $`col 04` , # `col 05` , # and ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 18) Output @@ -306,6 +320,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 19) Output @@ -327,6 +342,7 @@ # `col 05` , # and # abbreviated ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 20) Output @@ -348,6 +364,7 @@ # `col 05` , # and abbreviated # variable ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 21) Output @@ -369,6 +386,7 @@ # `col 05` , # and abbreviated # variable ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 22) Output @@ -389,6 +407,7 @@ # `col 05` , # and abbreviated # variable ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 23) Output @@ -409,6 +428,7 @@ # `col 05` , # and abbreviated # variable names ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 24) Output @@ -429,6 +449,7 @@ # `col 05` , and # abbreviated # variable names ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 25) Output @@ -449,6 +470,7 @@ # and abbreviated # variable names # 1: column_zero_zero, ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 26) Output @@ -469,6 +491,7 @@ # and abbreviated # variable names # 1: column_zero_zero, ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 27) Output @@ -489,6 +512,7 @@ # and abbreviated # variable names # 1: column_zero_zero, ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 28) Output @@ -509,6 +533,7 @@ # and abbreviated # variable names # 1: column_zero_zero, ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 29) Output @@ -529,6 +554,7 @@ # names # 1: column_zero_zero, # 2: `col 01`$`col 02`, ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 30) Output @@ -549,6 +575,7 @@ # names # 1: column_zero_zero, # 2: `col 01`$`col 02`, ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 31) Output @@ -569,6 +596,7 @@ # 1: column_zero_zero, # 2: `col 01`$`col 02`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 32) Output @@ -589,6 +617,7 @@ # 1: column_zero_zero, # 2: `col 01`$`col 02`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 33) Output @@ -609,6 +638,7 @@ # 1: column_zero_zero, # 2: `col 01`$`col 02`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 34) Output @@ -628,6 +658,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, # 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 35) Output @@ -647,6 +678,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, # 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 36) Output @@ -666,6 +698,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, # 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 37) Output @@ -685,6 +718,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, # 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 38) Output @@ -703,6 +737,7 @@ # $`col 04` , and # abbreviated variable names # 1: `col 01`$`col 02`, 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 39) Output @@ -721,6 +756,7 @@ # $`col 04` , and # abbreviated variable names # 1: `col 01`$`col 02`, 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 40) Output @@ -739,6 +775,7 @@ # $`col 04` , and # abbreviated variable names # 1: `col 01`$`col 02`, 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 41) Output @@ -757,6 +794,7 @@ # $`col 04` , and abbreviated # variable names 1: `col 01`$`col 02`, # 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 42) Output @@ -775,6 +813,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, 2: $`col 03`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 43) Output @@ -793,6 +832,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, 2: $`col 03`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 44) Output @@ -811,6 +851,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, 2: $`col 03`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 45) Output @@ -829,6 +870,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, 2: $`col 03`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 46) Output @@ -847,6 +889,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, 2: $`col 03`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 47) Output @@ -865,6 +908,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, 2: $`col 03`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 48) Output @@ -883,6 +927,7 @@ # abbreviated variable names # 1: `col 01`$`col 02`, 2: $`col 03`, # 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 49) Output @@ -900,6 +945,7 @@ # `col 01`$`col 04` , and abbreviated # variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 50) Output @@ -917,6 +963,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 51) Output @@ -934,6 +981,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 52) Output @@ -951,6 +999,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 53) Output @@ -968,6 +1017,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 54) Output @@ -985,6 +1035,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 55) Output @@ -1002,6 +1053,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, 2: $`col 03`, # 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 56) Output @@ -1019,6 +1071,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, 2: $`col 03`, # 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 57) Output @@ -1036,6 +1089,7 @@ # `col 01`$`col 04`[2:3] , and abbreviated # variable names 1: `col 01`$`col 02`, 2: $`col 03`, # 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 58) Output @@ -1052,6 +1106,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , # and abbreviated variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 59) Output @@ -1068,6 +1123,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , # and abbreviated variable names 1: `col 01`$`col 02`, # 2: $`col 03`, 3: $`col 04`[,"A"], 4: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 60) Output @@ -1084,6 +1140,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , # and abbreviated variable names 1: $`col 03`, # 2: $`col 04`[,"A"], 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 61) Output @@ -1100,6 +1157,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , # and abbreviated variable names 1: $`col 03`, # 2: $`col 04`[,"A"], 3: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 62) Output @@ -1116,6 +1174,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], # 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 63) Output @@ -1131,6 +1190,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 64) Output @@ -1146,6 +1206,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 65) Output @@ -1161,6 +1222,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 66) Output @@ -1176,6 +1238,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 67) Output @@ -1191,6 +1254,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 68) Output @@ -1206,6 +1270,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 69) Output @@ -1221,6 +1286,7 @@ # ... with 1 more variable: `col 01`$`col 04`[2:3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 70) Output @@ -1236,6 +1302,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 71) Output @@ -1251,6 +1318,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and # abbreviated variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 72) Output @@ -1266,6 +1334,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and abbreviated # variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 73) Output @@ -1281,6 +1350,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and abbreviated # variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 74) Output @@ -1296,6 +1366,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and abbreviated # variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 75) Output @@ -1311,6 +1382,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and abbreviated # variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 76) Output @@ -1326,6 +1398,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and abbreviated # variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 77) Output @@ -1341,6 +1414,7 @@ # ... with 1 more variable: `col 01`$`col 04`[3] , and abbreviated # variable names 1: $`col 04`[,"A"], 2: `col 05` + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 78) Output @@ -1567,6 +1641,7 @@ # qsec , vs , # am , gear , # carb + # i Use `colnames()` to see all variable names Code tbl_format_setup(as_tbl(trees), width = 30, n = 100) Output @@ -1680,6 +1755,7 @@ # ... with 2 variables: # a , b + # i Use `colnames()` to see all variable names Code # No columns tbl_format_setup(as_tbl(trees[character()]), width = 30, n = 5L) @@ -1702,6 +1778,7 @@ # Girth , # Height , # Volume + # i Use `colnames()` to see all variable names Code # No columns, unknown tbl_format_setup(as_unknown_rows(trees[, character()]), width = 30, n = 5L) @@ -1749,6 +1826,7 @@ # ... with 4 more variables: xxxefg , xxxhij , xxxklm , # xxxnop + # i Use `colnames()` to see all variable names # tbl_format_setup() for footnotes with min_title_chars = 4 @@ -1767,6 +1845,7 @@ # ... with 4 more variables: xxxefg , xxxhij , xxxklm , # xxxnop + # i Use `colnames()` to see all variable names # tbl_format_setup() for footnotes with UTF-8 output @@ -1785,4 +1864,5 @@ # … with 4 more variables: xxxefg , xxxhij , xxxklm , # xxxnop + # ℹ Use `colnames()` to see all variable names diff --git a/tests/testthat/_snaps/tbl-format.md b/tests/testthat/_snaps/tbl-format.md index f4390ed58..4af9686c3 100644 --- a/tests/testthat/_snaps/tbl-format.md +++ b/tests/testthat/_snaps/tbl-format.md @@ -68,6 +68,7 @@ # qsec , vs , # am , gear , # carb + # i Use `colnames()` to see all variable names Code print(as_tbl(mtcars), n = 30) Output @@ -161,6 +162,7 @@ 10 19.2 6 168. 123 3.92 3.44 # ... with 22 more rows, and 5 more # variables: qsec , ... + # i Use `colnames()` to see all variable names Code print(as_tbl(mtcars), width = 30, max_footer_lines = 3) Output @@ -180,6 +182,7 @@ # ... with 22 more rows, and # 7 more variables: # drat , wt , ... + # i Use `colnames()` to see all variable names Code rlang::with_options(tibble.print_min = 5, as_tbl(mtcars)) Output @@ -256,6 +259,7 @@ 10 19.2 6 168. 123 3.92 3.44 # ... with 22 more rows, and 5 more # variables: qsec , ... + # i Use `colnames()` to see all variable names Code print(tbl_format_setup(new_tbl(trees, pillar_focus = "Volume"), width = 30)) Output diff --git a/tests/testthat/_snaps/unicode/ctl_colonnade.md b/tests/testthat/_snaps/unicode/ctl_colonnade.md index bf36593a9..5a2739675 100644 --- a/tests/testthat/_snaps/unicode/ctl_colonnade.md +++ b/tests/testthat/_snaps/unicode/ctl_colonnade.md @@ -211,6 +211,7 @@ # … with 1 more # variable: # a$y  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 15, focus = "b") Output @@ -228,6 +229,7 @@ # more # variable: # a  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 10, focus = "b") Output @@ -246,6 +248,7 @@ # more # variable: # a  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 30, focus = "a") Output @@ -286,6 +289,7 @@ # more # variable: # b  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 10, focus = "a") Output @@ -305,6 +309,7 @@ # variables: # a$y , # b  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 30, focus = c("a", "b")) Output @@ -345,6 +350,7 @@ # more # variable: # a$y  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 10, focus = c("a", "b")) Output @@ -364,6 +370,7 @@ # variables: # a$y , # b  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 30, focus = c("a", "b")) Output @@ -390,6 +397,7 @@ # … with 1 more # variable: # a$y  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 15, focus = c("a", "b")) Output @@ -407,6 +415,7 @@ # more # variable: # a$y  + # ℹ Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 10, focus = c("a", "b")) Output @@ -425,4 +434,5 @@ # more # variable: # a  + # ℹ Use `colnames()` to see all variable names From a4c6a18b4e26babeeb4e3b56708407e19db02ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 8 Jul 2022 05:09:56 +0200 Subject: [PATCH 2/4] Prepare for rows advice --- R/tbl-format-footer.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/R/tbl-format-footer.R b/R/tbl-format-footer.R index 3d7aa6468..0cdfcee00 100644 --- a/R/tbl-format-footer.R +++ b/R/tbl-format-footer.R @@ -131,8 +131,18 @@ format_extra_vars <- function(extra_cols, extra_cols_total) { format_footer_advice <- function(x, setup) { if (length(setup$extra_cols) > 0) { - paste0(symbol$info, " Use `colnames()` to see all variable names") + cols <- "`colnames()` to see all variable names" + } else { + cols <- NULL } + + advice <- enum_collapse(cols) + + if (length(advice) == 0) { + return() + } + + paste0(symbol$info, " Use ", advice) } wrap_footer <- function(footer, setup, lines = setup$max_footer_lines, ellipsis = TRUE) { From f17818c6058540e1d3872abcbbcb6ac1faccf056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 8 Jul 2022 05:13:36 +0200 Subject: [PATCH 3/4] Give advice on number of rows --- R/tbl-format-footer.R | 10 ++++-- tests/testthat/_snaps/tbl-format-setup.md | 7 ++++- tests/testthat/_snaps/tbl-format.md | 37 ++++++++++++++++------- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/R/tbl-format-footer.R b/R/tbl-format-footer.R index 0cdfcee00..9946e54b9 100644 --- a/R/tbl-format-footer.R +++ b/R/tbl-format-footer.R @@ -136,13 +136,19 @@ format_footer_advice <- function(x, setup) { cols <- NULL } - advice <- enum_collapse(cols) + 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 ", advice) + paste0(symbol$info, " Use ", paste(advice, collapse = " ")) } wrap_footer <- function(footer, setup, lines = setup$max_footer_lines, ellipsis = TRUE) { diff --git a/tests/testthat/_snaps/tbl-format-setup.md b/tests/testthat/_snaps/tbl-format-setup.md index fab384c4d..da680680c 100644 --- a/tests/testthat/_snaps/tbl-format-setup.md +++ b/tests/testthat/_snaps/tbl-format-setup.md @@ -1617,6 +1617,7 @@ 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 # ... with 22 more rows + # i Use `print(n = ...)` to see more rows Code tbl_format_setup(as_tbl(mtcars), width = 30, n = 8) Output @@ -1641,7 +1642,7 @@ # qsec , vs , # am , gear , # carb - # i Use `colnames()` to see all variable names + # i Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names Code tbl_format_setup(as_tbl(trees), width = 30, n = 100) Output @@ -1744,6 +1745,7 @@ 10 11.2 75 19.9 # ... with more rows + # i Use `print(n = ...)` to see more rows Code # No rows tbl_format_setup(new_tbl(list(a = character(), b = logical())), width = 30) @@ -1765,6 +1767,7 @@ # A data frame: 31 x 0 + # i Use `print(n = ...)` to see more rows Code # No rows, unknown tbl_format_setup(as_unknown_rows(trees[integer(), ]), width = 30, n = 5L) @@ -1790,6 +1793,7 @@ # ... with at least 5 rows # total + # i Use `print(n = ...)` to see more rows Code # Long table, unknown tbl_format_setup(as_unknown_rows(new_tbl(list(a = seq.int(10000)))), n = 5L, @@ -1808,6 +1812,7 @@ 5 5 # ... with more rows + # i Use `print(n = ...)` to see more rows # tbl_format_setup() for footnotes diff --git a/tests/testthat/_snaps/tbl-format.md b/tests/testthat/_snaps/tbl-format.md index 4af9686c3..525509461 100644 --- a/tests/testthat/_snaps/tbl-format.md +++ b/tests/testthat/_snaps/tbl-format.md @@ -17,17 +17,26 @@ [12] "\033[90m 9\033[39m 11.1 80 22.6" [13] "\033[90m10\033[39m 11.2 75 19.9" [14] "\033[90m# ... with 21 more rows\033[39m" + [15] "\033[90m# i Use `print(n = ...)` to see more rows\033[39m" Code options(cli.num_colors = 1) format(as_tbl(trees)) Output - [1] "# A data frame: 31 x 3" " Girth Height Volume" - [3] " " " 1 8.3 70 10.3" - [5] " 2 8.6 65 10.3" " 3 8.8 63 10.2" - [7] " 4 10.5 72 16.4" " 5 10.7 81 18.8" - [9] " 6 10.8 83 19.7" " 7 11 66 15.6" - [11] " 8 11 75 18.2" " 9 11.1 80 22.6" - [13] "10 11.2 75 19.9" "# ... with 21 more rows" + [1] "# A data frame: 31 x 3" + [2] " Girth Height Volume" + [3] " " + [4] " 1 8.3 70 10.3" + [5] " 2 8.6 65 10.3" + [6] " 3 8.8 63 10.2" + [7] " 4 10.5 72 16.4" + [8] " 5 10.7 81 18.8" + [9] " 6 10.8 83 19.7" + [10] " 7 11 66 15.6" + [11] " 8 11 75 18.2" + [12] " 9 11.1 80 22.6" + [13] "10 11.2 75 19.9" + [14] "# ... with 21 more rows" + [15] "# i Use `print(n = ...)` to see more rows" # print() output @@ -48,6 +57,7 @@ 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 # ... with 22 more rows + # i Use `print(n = ...)` to see more rows Code print(as_tbl(mtcars), n = 8, width = 30) Output @@ -68,7 +78,7 @@ # qsec , vs , # am , gear , # carb - # i Use `colnames()` to see all variable names + # i Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names Code print(as_tbl(mtcars), n = 30) Output @@ -106,6 +116,7 @@ 29 15.8 8 351 264 4.22 3.17 14.5 0 1 5 4 30 19.7 6 145 175 3.62 2.77 15.5 0 1 5 6 # ... with 2 more rows + # i Use `print(n = ...)` to see more rows Code print(as_tbl(mtcars), n = 100) Output @@ -162,7 +173,7 @@ 10 19.2 6 168. 123 3.92 3.44 # ... with 22 more rows, and 5 more # variables: qsec , ... - # i Use `colnames()` to see all variable names + # i Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names Code print(as_tbl(mtcars), width = 30, max_footer_lines = 3) Output @@ -182,7 +193,7 @@ # ... with 22 more rows, and # 7 more variables: # drat , wt , ... - # i Use `colnames()` to see all variable names + # i Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names Code rlang::with_options(tibble.print_min = 5, as_tbl(mtcars)) Output @@ -200,6 +211,7 @@ 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 # ... with 22 more rows + # i Use `print(n = ...)` to see more rows Code rlang::with_options(tibble.print_max = 50, as_tbl(mtcars)) Output @@ -217,6 +229,7 @@ 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 # ... with 22 more rows + # i Use `print(n = ...)` to see more rows Code rlang::with_options(tibble.width = 30, as_tbl(mtcars)) Output @@ -234,6 +247,7 @@ 9 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 10 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 # ... with 22 more rows + # i Use `print(n = ...)` to see more rows --- @@ -259,7 +273,7 @@ 10 19.2 6 168. 123 3.92 3.44 # ... with 22 more rows, and 5 more # variables: qsec , ... - # i Use `colnames()` to see all variable names + # i Use `print(n = ...)` to see more rows, and `colnames()` to see all variable names Code print(tbl_format_setup(new_tbl(trees, pillar_focus = "Volume"), width = 30)) Output @@ -282,4 +296,5 @@ 10 11.2 75 19.9 # ... with 21 more rows + # i Use `print(n = ...)` to see more rows From 968bbd656212b5b866ab02fe2a1ffd07e906b933 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 8 Jul 2022 05:36:59 +0200 Subject: [PATCH 4/4] [create-pull-request] automated change (#568) Co-authored-by: krlmlr --- tests/testthat/_snaps/ansi/ctl_colonnade.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/_snaps/ansi/ctl_colonnade.md b/tests/testthat/_snaps/ansi/ctl_colonnade.md index b15e14f98..e5115111c 100644 --- a/tests/testthat/_snaps/ansi/ctl_colonnade.md +++ b/tests/testthat/_snaps/ansi/ctl_colonnade.md @@ -211,6 +211,7 @@ # ... with 1 more # variable: # a$y  + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 15, focus = "b") Output @@ -228,6 +229,7 @@ # more # variable: # a  + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 10, focus = "b") Output @@ -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 @@ -285,6 +288,7 @@ # more # variable: # b  + # i Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 10, focus = "a") Output @@ -303,6 +307,7 @@ # more # variables: # a$y , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 30, focus = c("a", "b")) Output @@ -343,6 +348,7 @@ # more # variable: # a$y  + # i Use `colnames()` to see all variable names Code tbl_format_setup(x, width = 10, focus = c("a", "b")) Output @@ -361,6 +367,7 @@ # more # variables: # a$y , ... + # i Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 30, focus = c("a", "b")) Output @@ -387,6 +394,7 @@ # ... with 1 more # variable: # a$y  + # i Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 15, focus = c("a", "b")) Output @@ -404,6 +412,7 @@ # more # variable: # a$y  + # i Use `colnames()` to see all variable names Code tbl_format_setup(x[2:1], width = 10, focus = c("a", "b")) Output @@ -421,4 +430,5 @@ # 1 # more # variable: ... + # i Use `colnames()` to see all variable names