From 7c209c22b19ccd1a10e837ae9acf9a8dfcfd43df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 22 Jan 2022 08:22:59 +0100 Subject: [PATCH 1/6] Vector of title strings --- R/ctl_colonnade.R | 24 ++++---- R/ctl_compound.R | 18 ++---- R/ctl_new_pillar.R | 10 +++- R/tick.R | 8 +++ tests/testthat/_snaps/tbl-format-setup.md | 72 +++++++++++++++++++++++ 5 files changed, 103 insertions(+), 29 deletions(-) diff --git a/R/ctl_colonnade.R b/R/ctl_colonnade.R index 5caa70f1b..4959b9c2a 100644 --- a/R/ctl_colonnade.R +++ b/R/ctl_colonnade.R @@ -192,10 +192,16 @@ new_emit_pillars_callbacks <- function(controller, ) } -do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NULL, parent_col_idx = 1L) { +do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NULL, parent_col_idx = NULL) { top_level <- is.null(first_pillar) - pillar_list <- ctl_new_pillar_list(cb$controller, x, width = tier_widths, title = title, first_pillar = first_pillar) + # Only tweaking sub-title, because full title is needed for extra-cols + sub_title <- title + if (!is.null(sub_title)) { + sub_title[-length(sub_title)][parent_col_idx[-1] != 1] <- "" + } + + pillar_list <- ctl_new_pillar_list(cb$controller, x, width = tier_widths, title = sub_title, first_pillar = first_pillar) # Extra columns are known early on, and remain fixed extra <- attr(pillar_list, "extra") @@ -252,16 +258,6 @@ do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NUL x_pos <- 0L tier_pos <- 1L - # FIXME: Replace with title vector - sub_title <- title - if (!is.null(sub_title)) { - if (parent_col_idx >= 2) { - sub_title[[length(sub_title)]] <- "$" - } else { - sub_title[[length(sub_title)]] <- paste0(sub_title[[length(sub_title)]], "$") - } - } - # Advance column by column for (col in seq_along(pillar_list)) { target_tier <- rev$tier[[col]] @@ -286,9 +282,9 @@ do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NUL x[[col]], sub_tier_widths, cb, - c(sub_title, tick_if_needed(names(x)[[col]])), + c(title, tick_if_needed(names(x)[[col]])), pillar_list[[col]], - col + c(parent_col_idx, col) ) "!!!!!DEBUG used" diff --git a/R/ctl_compound.R b/R/ctl_compound.R index 87cd20040..10d866d41 100644 --- a/R/ctl_compound.R +++ b/R/ctl_compound.R @@ -18,27 +18,15 @@ new_data_frame_pillar_list <- function(x, controller, width, title, first_pillar for (i in seq_along(x)) { "!!!!!DEBUG i = `i`, width = `width`" - # FIXME - # sub_title <- c(title, ticked_names[[i]]) if (i == 1 && !is.null(first_pillar)) { pillar <- first_pillar } else { - sub_title <- ticked_names[[i]] - if (!is.null(title)) { - if (i == 1) { - title[[length(title)]] <- paste0(title[[length(title)]], "$") - } else { - title[[length(title)]] <- "$" - } - sub_title <- c(title, sub_title) - } - # Call ctl_new_pillar_list(), return only the first sub-pillar # thanks to width = NULL new_pillars <- ctl_new_pillar_list( controller, x[[i]], width = NULL, - title = sub_title + title = c(title, ticked_names[[i]]) ) # Safety check: @@ -67,6 +55,10 @@ new_data_frame_pillar_list <- function(x, controller, width, title, first_pillar } pillars[[i]] <- pillar + + if (!is.null(title)) { + title[] <- "" + } } pillars <- compact(pillars) diff --git a/R/ctl_new_pillar.R b/R/ctl_new_pillar.R index f8bd86424..d108b2921 100644 --- a/R/ctl_new_pillar.R +++ b/R/ctl_new_pillar.R @@ -147,7 +147,13 @@ ctl_new_pillar_list.tbl <- function(controller, x, width, ..., title = NULL, fir } } -# FIXME: Keep vectorized titles later prepare_title <- function(title) { - paste(title, collapse = "") + n_title <- length(title) + if (n_title == 0) { + title + } else if (grepl("^[[]", title[[n_title]])) { + paste0(paste(title[-n_title], collapse = "$"), title[[n_title]]) + } else { + paste(title, collapse = "$") + } } diff --git a/R/tick.R b/R/tick.R index 7ff43f9f2..6fa60ac45 100644 --- a/R/tick.R +++ b/R/tick.R @@ -23,12 +23,20 @@ format_title <- function(x, width) { } tick_if_needed <- function(x) { + # Compatibility with R 3.4 + if (is.null(x)) { + return(NULL) + } needs_ticks <- !is_syntactic(x) x[needs_ticks] <- tick(x[needs_ticks]) x } is_syntactic <- function(x) { + # Compatibility with R 3.4 + if (is.null(x)) { + return(logical()) + } ret <- make.names(x) == x ret[is.na(x)] <- FALSE ret diff --git a/tests/testthat/_snaps/tbl-format-setup.md b/tests/testthat/_snaps/tbl-format-setup.md index bd57f9366..00b2671ed 100644 --- a/tests/testthat/_snaps/tbl-format-setup.md +++ b/tests/testthat/_snaps/tbl-format-setup.md @@ -967,6 +967,8 @@ Code tbl_format_setup(x, width = 68) + Warning + number of items to replace is not a multiple of replacement length Output @@ -980,6 +982,8 @@ Code tbl_format_setup(x, width = 69) + Warning + number of items to replace is not a multiple of replacement length Output @@ -993,6 +997,8 @@ Code tbl_format_setup(x, width = 70) + Warning + number of items to replace is not a multiple of replacement length Output @@ -1006,6 +1012,8 @@ Code tbl_format_setup(x, width = 71) + Warning + number of items to replace is not a multiple of replacement length Output @@ -1019,6 +1027,8 @@ Code tbl_format_setup(x, width = 72) + Warning + number of items to replace is not a multiple of replacement length Output @@ -1032,6 +1042,8 @@ Code tbl_format_setup(x, width = 73) + Warning + number of items to replace is not a multiple of replacement length Output @@ -1045,6 +1057,8 @@ Code tbl_format_setup(x, width = 74) + Warning + number of items to replace is not a multiple of replacement length Output @@ -1058,6 +1072,9 @@ Code tbl_format_setup(x, width = 75) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1071,6 +1088,9 @@ Code tbl_format_setup(x, width = 76) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1084,6 +1104,9 @@ Code tbl_format_setup(x, width = 77) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1097,6 +1120,9 @@ Code tbl_format_setup(x, width = 78) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1110,6 +1136,9 @@ Code tbl_format_setup(x, width = 79) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1123,6 +1152,9 @@ Code tbl_format_setup(x, width = 80) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1136,6 +1168,10 @@ Code tbl_format_setup(x, width = 81) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1154,6 +1190,10 @@ Code tbl_format_setup(x, width = 82) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1172,6 +1212,10 @@ Code tbl_format_setup(x, width = 83) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1190,6 +1234,10 @@ Code tbl_format_setup(x, width = 84) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1208,6 +1256,10 @@ Code tbl_format_setup(x, width = 85) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1226,6 +1278,10 @@ Code tbl_format_setup(x, width = 86) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1244,6 +1300,10 @@ Code tbl_format_setup(x, width = 87) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1262,6 +1322,10 @@ Code tbl_format_setup(x, width = 88) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1280,6 +1344,10 @@ Code tbl_format_setup(x, width = 89) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output @@ -1298,6 +1366,10 @@ Code tbl_format_setup(x, width = Inf) + Warning + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length + number of items to replace is not a multiple of replacement length Output From 7d45f7d5dd0d62ed3b2534b5045729d5d13d21c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 22 Jan 2022 10:00:01 +0100 Subject: [PATCH 2/6] Show names of missing nested columns --- R/ctl_colonnade.R | 28 ++++--- R/tick.R | 5 ++ tests/testthat/_snaps/tbl-format-setup.md | 96 ++++++++++++++++++++--- 3 files changed, 108 insertions(+), 21 deletions(-) diff --git a/R/ctl_colonnade.R b/R/ctl_colonnade.R index 4959b9c2a..0134f7562 100644 --- a/R/ctl_colonnade.R +++ b/R/ctl_colonnade.R @@ -56,11 +56,15 @@ ctl_colonnade <- function(x, has_row_id = TRUE, width = NULL, # print(extra_cols) # FIXME: Show for all levels - is_top_level <- map_lgl(my_extra_cols$x, identical, x) - if (any(is_top_level)) { - extra_cols <<- as.list(x)[my_extra_cols$cols[is_top_level][[1]]] - names(extra_cols) <<- tick_if_needed(names(extra_cols)) - } + out <- pmap(my_extra_cols, function(x, title, cols) { + out <- as.list(x)[cols] + if (!is.null(title)) { + names(out) <- paste0(paste0(title, "$", collapse = ""), names(out)) + } + out + }) + + extra_cols <<- unlist(out, recursive = FALSE) } cb <- new_emit_tiers_callbacks( @@ -69,10 +73,6 @@ ctl_colonnade <- function(x, has_row_id = TRUE, width = NULL, ) do_emit_tiers(x_focus, tier_widths, length(focus), cb) - if (length(extra_cols) == 0) { - extra_cols <- list() - } - new_colonnade_body(formatted_tiers, split_after = split_after, extra_cols = extra_cols) } @@ -156,9 +156,11 @@ do_emit_tiers <- function(x, tier_widths, n_focus, cb) { # message("extra_cols()") # print(title) # print(cols) - extra_cols <<- vec_rbind(extra_cols, data_frame( + new_extra_cols <- data_frame( x = list(x), title = list(title), cols = list(cols) - )) + ) + # Add to the front, because top-level columns are emitted first: + extra_cols <<- vec_rbind(new_extra_cols, extra_cols) } cb_pillars <- new_emit_pillars_callbacks( @@ -206,8 +208,10 @@ do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NUL # Extra columns are known early on, and remain fixed extra <- attr(pillar_list, "extra") + # We emit early, this means that top-level columns are emitted before + # nested columns. We reverse in the callback. if (length(extra) > 0) { - cb$on_extra_cols(x, title, extra) + cb$on_extra_cols(tick_names_if_needed(x), title, tick_if_needed(extra)) } if (length(pillar_list) == 0) { diff --git a/R/tick.R b/R/tick.R index 6fa60ac45..4533f082e 100644 --- a/R/tick.R +++ b/R/tick.R @@ -22,6 +22,11 @@ format_title <- function(x, width) { out } +tick_names_if_needed <- function(x) { + names(x) <- tick_if_needed(names(x)) + x +} + tick_if_needed <- function(x) { # Compatibility with R 3.4 if (is.null(x)) { diff --git a/tests/testthat/_snaps/tbl-format-setup.md b/tests/testthat/_snaps/tbl-format-setup.md index 00b2671ed..0e1b7e514 100644 --- a/tests/testthat/_snaps/tbl-format-setup.md +++ b/tests/testthat/_snaps/tbl-format-setup.md @@ -532,7 +532,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 36) @@ -547,7 +549,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 37) @@ -562,7 +566,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 38) @@ -577,7 +583,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 39) @@ -592,7 +600,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 40) @@ -607,7 +617,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 41) @@ -622,7 +634,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 42) @@ -637,7 +651,9 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , # `col 05` Code tbl_format_setup(x, width = 43) @@ -652,7 +668,10 @@ 2 2.23 b 3 3.23 c - # ... with 1 more variable: `col 05` + # ... with 3 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` , + # `col 05` Code tbl_format_setup(x, width = 44) Output @@ -666,6 +685,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 45) Output @@ -679,6 +701,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 46) Output @@ -692,6 +717,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 47) Output @@ -705,6 +733,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 48) Output @@ -718,6 +749,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 49) Output @@ -731,6 +765,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 50) Output @@ -744,6 +781,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 51) Output @@ -757,6 +797,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 52) Output @@ -770,6 +813,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 53) Output @@ -783,6 +829,9 @@ 2 2.23 b b 3 3.23 c c + # ... with 2 more variables: + # `col 01`$`col 03` , + # `col 01`$`col 04` Code tbl_format_setup(x, width = 54) Output @@ -796,6 +845,8 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: + # `col 01`$`col 04` Code tbl_format_setup(x, width = 55) Output @@ -809,6 +860,8 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: + # `col 01`$`col 04` Code tbl_format_setup(x, width = 56) Output @@ -822,6 +875,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 57) Output @@ -835,6 +889,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 58) Output @@ -848,6 +903,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 59) Output @@ -861,6 +917,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 60) Output @@ -874,6 +931,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 61) Output @@ -887,6 +945,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 62) Output @@ -900,6 +959,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 63) Output @@ -913,6 +973,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 64) Output @@ -926,6 +987,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 65) Output @@ -939,6 +1001,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 66) Output @@ -952,6 +1015,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 67) Output @@ -965,6 +1029,7 @@ 2 2.23 b B b 3 3.23 c C c + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 68) Warning @@ -980,6 +1045,7 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c + # ... with 2 more variables: `col 01`$`col 04`$ , NA Code tbl_format_setup(x, width = 69) Warning @@ -995,6 +1061,7 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c + # ... with 2 more variables: `col 01`$`col 04`$ , NA Code tbl_format_setup(x, width = 70) Warning @@ -1010,6 +1077,7 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c + # ... with 2 more variables: `col 01`$`col 04`$ , NA Code tbl_format_setup(x, width = 71) Warning @@ -1025,6 +1093,7 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c + # ... with 2 more variables: `col 01`$`col 04`$ , NA Code tbl_format_setup(x, width = 72) Warning @@ -1040,6 +1109,7 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c + # ... with 2 more variables: `col 01`$`col 04`$ , NA Code tbl_format_setup(x, width = 73) Warning @@ -1055,6 +1125,7 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c + # ... with 2 more variables: `col 01`$`col 04`$ , NA Code tbl_format_setup(x, width = 74) Warning @@ -1070,6 +1141,7 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c + # ... with 2 more variables: `col 01`$`col 04`$ , NA Code tbl_format_setup(x, width = 75) Warning @@ -1086,6 +1158,7 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`$ Code tbl_format_setup(x, width = 76) Warning @@ -1102,6 +1175,7 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`$ Code tbl_format_setup(x, width = 77) Warning @@ -1118,6 +1192,7 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`$ Code tbl_format_setup(x, width = 78) Warning @@ -1134,6 +1209,7 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`$ Code tbl_format_setup(x, width = 79) Warning @@ -1150,6 +1226,7 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`$ Code tbl_format_setup(x, width = 80) Warning @@ -1166,6 +1243,7 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`$ Code tbl_format_setup(x, width = 81) Warning From 9e59b3ed25cffc97629c5f8a1342bde3a8b6ccd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Jan 2022 05:12:54 +0100 Subject: [PATCH 3/6] Abbreviate repeated top-level column names --- R/ctl_colonnade.R | 5 ++- tests/testthat/_snaps/tbl-format-setup.md | 47 +++++++++-------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/R/ctl_colonnade.R b/R/ctl_colonnade.R index 0134f7562..e6c49d95b 100644 --- a/R/ctl_colonnade.R +++ b/R/ctl_colonnade.R @@ -59,7 +59,10 @@ ctl_colonnade <- function(x, has_row_id = TRUE, width = NULL, out <- pmap(my_extra_cols, function(x, title, cols) { out <- as.list(x)[cols] if (!is.null(title)) { - names(out) <- paste0(paste0(title, "$", collapse = ""), names(out)) + title_empty <- rep_along(title, "") + new_names <- paste0(paste0(title_empty, "$", collapse = ""), names(out)) + new_names[[1]] <- paste0(paste0(title, "$", collapse = ""), names(out)[[1]]) + names(out) <- new_names } out }) diff --git a/tests/testthat/_snaps/tbl-format-setup.md b/tests/testthat/_snaps/tbl-format-setup.md index 0e1b7e514..41d6cd6c4 100644 --- a/tests/testthat/_snaps/tbl-format-setup.md +++ b/tests/testthat/_snaps/tbl-format-setup.md @@ -534,7 +534,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , + # $`col 04` , # `col 05` Code tbl_format_setup(x, width = 36) @@ -551,7 +551,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , + # $`col 04` , # `col 05` Code tbl_format_setup(x, width = 37) @@ -568,7 +568,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , + # $`col 04` , # `col 05` Code tbl_format_setup(x, width = 38) @@ -585,7 +585,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , + # $`col 04` , # `col 05` Code tbl_format_setup(x, width = 39) @@ -602,7 +602,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , + # $`col 04` , # `col 05` Code tbl_format_setup(x, width = 40) @@ -619,8 +619,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , - # `col 05` + # $`col 04` , `col 05` Code tbl_format_setup(x, width = 41) Output @@ -636,8 +635,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , - # `col 05` + # $`col 04` , `col 05` Code tbl_format_setup(x, width = 42) Output @@ -653,8 +651,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , - # `col 05` + # $`col 04` , `col 05` Code tbl_format_setup(x, width = 43) Output @@ -670,8 +667,7 @@ # ... with 3 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` , - # `col 05` + # $`col 04` , `col 05` Code tbl_format_setup(x, width = 44) Output @@ -687,7 +683,7 @@ # ... with 2 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` + # $`col 04` Code tbl_format_setup(x, width = 45) Output @@ -703,7 +699,7 @@ # ... with 2 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` + # $`col 04` Code tbl_format_setup(x, width = 46) Output @@ -719,7 +715,7 @@ # ... with 2 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` + # $`col 04` Code tbl_format_setup(x, width = 47) Output @@ -735,7 +731,7 @@ # ... with 2 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` + # $`col 04` Code tbl_format_setup(x, width = 48) Output @@ -751,7 +747,7 @@ # ... with 2 more variables: # `col 01`$`col 03` , - # `col 01`$`col 04` + # $`col 04` Code tbl_format_setup(x, width = 49) Output @@ -766,8 +762,7 @@ 3 3.23 c c # ... with 2 more variables: - # `col 01`$`col 03` , - # `col 01`$`col 04` + # `col 01`$`col 03` , $`col 04` Code tbl_format_setup(x, width = 50) Output @@ -782,8 +777,7 @@ 3 3.23 c c # ... with 2 more variables: - # `col 01`$`col 03` , - # `col 01`$`col 04` + # `col 01`$`col 03` , $`col 04` Code tbl_format_setup(x, width = 51) Output @@ -798,8 +792,7 @@ 3 3.23 c c # ... with 2 more variables: - # `col 01`$`col 03` , - # `col 01`$`col 04` + # `col 01`$`col 03` , $`col 04` Code tbl_format_setup(x, width = 52) Output @@ -814,8 +807,7 @@ 3 3.23 c c # ... with 2 more variables: - # `col 01`$`col 03` , - # `col 01`$`col 04` + # `col 01`$`col 03` , $`col 04` Code tbl_format_setup(x, width = 53) Output @@ -830,8 +822,7 @@ 3 3.23 c c # ... with 2 more variables: - # `col 01`$`col 03` , - # `col 01`$`col 04` + # `col 01`$`col 03` , $`col 04` Code tbl_format_setup(x, width = 54) Output From a6bdc019f04a55c6b4e13725e4688ae3ce6c752b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Jan 2022 08:36:11 +0100 Subject: [PATCH 4/6] Show names of extra columns for packed matrices --- R/ctl_colonnade.R | 26 +++++- tests/testthat/_snaps/tbl-format-setup.md | 98 +++-------------------- 2 files changed, 35 insertions(+), 89 deletions(-) diff --git a/R/ctl_colonnade.R b/R/ctl_colonnade.R index e6c49d95b..7d30b6f40 100644 --- a/R/ctl_colonnade.R +++ b/R/ctl_colonnade.R @@ -55,14 +55,20 @@ ctl_colonnade <- function(x, has_row_id = TRUE, width = NULL, on_extra_cols <- function(my_extra_cols) { # print(extra_cols) - # FIXME: Show for all levels out <- pmap(my_extra_cols, function(x, title, cols) { out <- as.list(x)[cols] - if (!is.null(title)) { + if (is.null(title)) { + return(out) + } + + if (length(out) > 1) { title_empty <- rep_along(title, "") new_names <- paste0(paste0(title_empty, "$", collapse = ""), names(out)) new_names[[1]] <- paste0(paste0(title, "$", collapse = ""), names(out)[[1]]) names(out) <- new_names + } else { + # Also account for the case of packed matrices here + names(out) <- prepare_title(c(title, names(out))) } out }) @@ -214,7 +220,19 @@ do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NUL # We emit early, this means that top-level columns are emitted before # nested columns. We reverse in the callback. if (length(extra) > 0) { - cb$on_extra_cols(tick_names_if_needed(x), title, tick_if_needed(extra)) + if (is.numeric(extra)) { + if (length(extra) == 1) { + extra <- paste0("[", extra, "]") + } else { + extra <- paste0("[", min(extra), ":", max(extra), "]") + } + x_extra <- set_names(list(x[1,]), extra) + } else { + extra <- tick_if_needed(extra) + x_extra <- tick_names_if_needed(x) + } + + cb$on_extra_cols(x_extra, title, extra) } if (length(pillar_list) == 0) { @@ -291,7 +309,7 @@ do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NUL cb, c(title, tick_if_needed(names(x)[[col]])), pillar_list[[col]], - c(parent_col_idx, col) + c(parent_col_idx, if (!is.null(names(x))) col) ) "!!!!!DEBUG used" diff --git a/tests/testthat/_snaps/tbl-format-setup.md b/tests/testthat/_snaps/tbl-format-setup.md index 41d6cd6c4..96dff3c3d 100644 --- a/tests/testthat/_snaps/tbl-format-setup.md +++ b/tests/testthat/_snaps/tbl-format-setup.md @@ -1023,8 +1023,6 @@ # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 68) - Warning - number of items to replace is not a multiple of replacement length Output @@ -1036,11 +1034,9 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c - # ... with 2 more variables: `col 01`$`col 04`$ , NA + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 69) - Warning - number of items to replace is not a multiple of replacement length Output @@ -1052,11 +1048,9 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c - # ... with 2 more variables: `col 01`$`col 04`$ , NA + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 70) - Warning - number of items to replace is not a multiple of replacement length Output @@ -1068,11 +1062,9 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c - # ... with 2 more variables: `col 01`$`col 04`$ , NA + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 71) - Warning - number of items to replace is not a multiple of replacement length Output @@ -1084,11 +1076,9 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c - # ... with 2 more variables: `col 01`$`col 04`$ , NA + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 72) - Warning - number of items to replace is not a multiple of replacement length Output @@ -1100,11 +1090,9 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c - # ... with 2 more variables: `col 01`$`col 04`$ , NA + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 73) - Warning - number of items to replace is not a multiple of replacement length Output @@ -1116,11 +1104,9 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c - # ... with 2 more variables: `col 01`$`col 04`$ , NA + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 74) - Warning - number of items to replace is not a multiple of replacement length Output @@ -1132,12 +1118,9 @@ 2 2.23 b B 2 b 3 3.23 c C 3 c - # ... with 2 more variables: `col 01`$`col 04`$ , NA + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 75) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1149,12 +1132,9 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c - # ... with 1 more variable: `col 01`$`col 04`$ + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 76) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1166,12 +1146,9 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c - # ... with 1 more variable: `col 01`$`col 04`$ + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 77) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1183,12 +1160,9 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c - # ... with 1 more variable: `col 01`$`col 04`$ + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 78) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1200,12 +1174,9 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c - # ... with 1 more variable: `col 01`$`col 04`$ + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 79) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1217,12 +1188,9 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c - # ... with 1 more variable: `col 01`$`col 04`$ + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 80) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1234,13 +1202,9 @@ 2 2.23 b B 2 5 b 3 3.23 c C 3 6 c - # ... with 1 more variable: `col 01`$`col 04`$ + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 81) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1259,10 +1223,6 @@ Code tbl_format_setup(x, width = 82) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1281,10 +1241,6 @@ Code tbl_format_setup(x, width = 83) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1303,10 +1259,6 @@ Code tbl_format_setup(x, width = 84) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1325,10 +1277,6 @@ Code tbl_format_setup(x, width = 85) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1347,10 +1295,6 @@ Code tbl_format_setup(x, width = 86) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1369,10 +1313,6 @@ Code tbl_format_setup(x, width = 87) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1391,10 +1331,6 @@ Code tbl_format_setup(x, width = 88) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1413,10 +1349,6 @@ Code tbl_format_setup(x, width = 89) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output @@ -1435,10 +1367,6 @@ Code tbl_format_setup(x, width = Inf) - Warning - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length - number of items to replace is not a multiple of replacement length Output From a6bf7fb70ecfe3b2a4153a077c0d7668f3620bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Jan 2022 08:39:46 +0100 Subject: [PATCH 5/6] Use named matrix --- tests/testthat/_snaps/tbl-format-setup.md | 299 +++++++++------------- tests/testthat/test-tbl-format-setup.R | 3 +- 2 files changed, 130 insertions(+), 172 deletions(-) diff --git a/tests/testthat/_snaps/tbl-format-setup.md b/tests/testthat/_snaps/tbl-format-setup.md index 96dff3c3d..315cbeff1 100644 --- a/tests/testthat/_snaps/tbl-format-setup.md +++ b/tests/testthat/_snaps/tbl-format-setup.md @@ -1,6 +1,7 @@ # output test Code + options(width = 100) tbl_format_setup(x, width = 4) Output @@ -1028,13 +1029,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col ~` $`col 03` $`col 04`[,1] `col 05` - - 1 1.23 a A 1 a - 2 2.23 b B 2 b - 3 3.23 c C 3 c + column_zero_zero `col 01`$`col 02` $`col 03` `col 05` + + 1 1.23 a A a + 2 2.23 b B b + 3 3.23 c C c - # ... with 1 more variable: `col 01`$`col 04`[2:3] + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 69) Output @@ -1042,13 +1043,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] `col 05` - - 1 1.23 a A 1 a - 2 2.23 b B 2 b - 3 3.23 c C 3 c + column_zero_zero `col 01`$`col 02` $`col 03` `col 05` + + 1 1.23 a A a + 2 2.23 b B b + 3 3.23 c C c - # ... with 1 more variable: `col 01`$`col 04`[2:3] + # ... with 1 more variable: `col 01`$`col 04` Code tbl_format_setup(x, width = 70) Output @@ -1056,11 +1057,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] `col 05` - - 1 1.23 a A 1 a - 2 2.23 b B 2 b - 3 3.23 c C 3 c + column_zero_zero `col 01`$`col ~` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c # ... with 1 more variable: `col 01`$`col 04`[2:3] Code @@ -1070,11 +1071,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] `col 05` - - 1 1.23 a A 1 a - 2 2.23 b B 2 b - 3 3.23 c C 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c # ... with 1 more variable: `col 01`$`col 04`[2:3] Code @@ -1084,11 +1085,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] `col 05` - - 1 1.23 a A 1 a - 2 2.23 b B 2 b - 3 3.23 c C 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c # ... with 1 more variable: `col 01`$`col 04`[2:3] Code @@ -1098,11 +1099,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] `col 05` - - 1 1.23 a A 1 a - 2 2.23 b B 2 b - 3 3.23 c C 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c # ... with 1 more variable: `col 01`$`col 04`[2:3] Code @@ -1112,11 +1113,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] `col 05` - - 1 1.23 a A 1 a - 2 2.23 b B 2 b - 3 3.23 c C 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c # ... with 1 more variable: `col 01`$`col 04`[2:3] Code @@ -1126,13 +1127,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] `col 05` - - 1 1.23 a A 1 4 a - 2 2.23 b B 2 5 b - 3 3.23 c C 3 6 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c - # ... with 1 more variable: `col 01`$`col 04`[3] + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 76) Output @@ -1140,13 +1141,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] `col 05` - - 1 1.23 a A 1 4 a - 2 2.23 b B 2 5 b - 3 3.23 c C 3 6 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c - # ... with 1 more variable: `col 01`$`col 04`[3] + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 77) Output @@ -1154,13 +1155,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] `col 05` - - 1 1.23 a A 1 4 a - 2 2.23 b B 2 5 b - 3 3.23 c C 3 6 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c - # ... with 1 more variable: `col 01`$`col 04`[3] + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 78) Output @@ -1168,13 +1169,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] `col 05` - - 1 1.23 a A 1 4 a - 2 2.23 b B 2 5 b - 3 3.23 c C 3 6 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] `col 05` + + 1 1.23 a A 1 a + 2 2.23 b B 2 b + 3 3.23 c C 3 c - # ... with 1 more variable: `col 01`$`col 04`[3] + # ... with 1 more variable: `col 01`$`col 04`[2:3] Code tbl_format_setup(x, width = 79) Output @@ -1182,11 +1183,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] `col 05` - - 1 1.23 a A 1 4 a - 2 2.23 b B 2 5 b - 3 3.23 c C 3 6 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c # ... with 1 more variable: `col 01`$`col 04`[3] Code @@ -1196,11 +1197,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] `col 05` - - 1 1.23 a A 1 4 a - 2 2.23 b B 2 5 b - 3 3.23 c C 3 6 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c # ... with 1 more variable: `col 01`$`col 04`[3] Code @@ -1210,17 +1211,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 82) Output @@ -1228,17 +1225,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 83) Output @@ -1246,17 +1239,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 84) Output @@ -1264,17 +1253,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 85) Output @@ -1282,17 +1267,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 86) Output @@ -1300,17 +1281,13 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] `col 05` + + 1 1.23 a A 1 4 a + 2 2.23 b B 2 5 b + 3 3.23 c C 3 6 c + # ... with 1 more variable: `col 01`$`col 04`[3] Code tbl_format_setup(x, width = 87) Output @@ -1318,16 +1295,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] $[,"C"] `col 05` + + 1 1.23 a A 1 4 7 a + 2 2.23 b B 2 5 8 b + 3 3.23 c C 3 6 9 c Code tbl_format_setup(x, width = 88) @@ -1336,16 +1308,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] $[,"C"] `col 05` + + 1 1.23 a A 1 4 7 a + 2 2.23 b B 2 5 8 b + 3 3.23 c C 3 6 9 c Code tbl_format_setup(x, width = 89) @@ -1354,16 +1321,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] $[,"C"] `col 05` + + 1 1.23 a A 1 4 7 a + 2 2.23 b B 2 5 8 b + 3 3.23 c C 3 6 9 c Code tbl_format_setup(x, width = Inf) @@ -1372,16 +1334,11 @@ # A data frame: 3 x 3 - column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,1] $[,2] $[,3] - - 1 1.23 a A 1 4 7 - 2 2.23 b B 2 5 8 - 3 3.23 c C 3 6 9 - `col 05` - - 1 a - 2 b - 3 c + column_zero_zero `col 01`$`col 02` $`col 03` $`col 04`[,"A"] $[,"B"] $[,"C"] `col 05` + + 1 1.23 a A 1 4 7 a + 2 2.23 b B 2 5 8 b + 3 3.23 c C 3 6 9 c # tbl_format_setup() results diff --git a/tests/testthat/test-tbl-format-setup.R b/tests/testthat/test-tbl-format-setup.R index 823cd9356..ef736ba82 100644 --- a/tests/testthat/test-tbl-format-setup.R +++ b/tests/testthat/test-tbl-format-setup.R @@ -4,12 +4,13 @@ test_that("output test", { `col 01` = new_tbl(list( `col 02` = letters[1:3], `col 03` = LETTERS[1:3], - `col 04` = matrix(1:9, nrow = 3) + `col 04` = matrix(1:9, nrow = 3, dimnames = list(letters[1:3], LETTERS[1:3])) )), `col 05` = ordered(letters[1:3]) )) expect_snapshot({ + options(width = 100) tbl_format_setup(x, width = 4) tbl_format_setup(x, width = 5) tbl_format_setup(x, width = 6) From d5eb8df0699c9cbf5aff8d83c655d4fd8102d45c Mon Sep 17 00:00:00 2001 From: krlmlr Date: Sun, 23 Jan 2022 07:42:44 +0000 Subject: [PATCH 6/6] Auto-update from GitHub Actions Run: https://github.com/r-lib/pillar/actions/runs/1735316008 --- R/ctl_colonnade.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ctl_colonnade.R b/R/ctl_colonnade.R index 7d30b6f40..4d819284f 100644 --- a/R/ctl_colonnade.R +++ b/R/ctl_colonnade.R @@ -226,7 +226,7 @@ do_emit_pillars <- function(x, tier_widths, cb, title = NULL, first_pillar = NUL } else { extra <- paste0("[", min(extra), ":", max(extra), "]") } - x_extra <- set_names(list(x[1,]), extra) + x_extra <- set_names(list(x[1, ]), extra) } else { extra <- tick_if_needed(extra) x_extra <- tick_names_if_needed(x)