Skip to content

Commit

Permalink
Abbreviate repeated top-level column names
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Jan 23, 2022
1 parent fe54d9b commit 5508951
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
5 changes: 4 additions & 1 deletion R/ctl_colonnade.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
47 changes: 19 additions & 28 deletions tests/testthat/_snaps/tbl-format-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# $`col 04` <tbl[,2]>,
# `col 05` <ord>
Code
tbl_format_setup(x, width = 36)
Expand All @@ -551,7 +551,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# $`col 04` <tbl[,2]>,
# `col 05` <ord>
Code
tbl_format_setup(x, width = 37)
Expand All @@ -568,7 +568,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# $`col 04` <tbl[,2]>,
# `col 05` <ord>
Code
tbl_format_setup(x, width = 38)
Expand All @@ -585,7 +585,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# $`col 04` <tbl[,2]>,
# `col 05` <ord>
Code
tbl_format_setup(x, width = 39)
Expand All @@ -602,7 +602,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# $`col 04` <tbl[,2]>,
# `col 05` <ord>
Code
tbl_format_setup(x, width = 40)
Expand All @@ -619,8 +619,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# `col 05` <ord>
# $`col 04` <tbl[,2]>, `col 05` <ord>
Code
tbl_format_setup(x, width = 41)
Output
Expand All @@ -636,8 +635,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# `col 05` <ord>
# $`col 04` <tbl[,2]>, `col 05` <ord>
Code
tbl_format_setup(x, width = 42)
Output
Expand All @@ -653,8 +651,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# `col 05` <ord>
# $`col 04` <tbl[,2]>, `col 05` <ord>
Code
tbl_format_setup(x, width = 43)
Output
Expand All @@ -670,8 +667,7 @@
<tbl_format_footer(setup)>
# ... with 3 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>,
# `col 05` <ord>
# $`col 04` <tbl[,2]>, `col 05` <ord>
Code
tbl_format_setup(x, width = 44)
Output
Expand All @@ -687,7 +683,7 @@
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 45)
Output
Expand All @@ -703,7 +699,7 @@
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 46)
Output
Expand All @@ -719,7 +715,7 @@
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 47)
Output
Expand All @@ -735,7 +731,7 @@
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 48)
Output
Expand All @@ -751,7 +747,7 @@
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 49)
Output
Expand All @@ -766,8 +762,7 @@
3 3.23 c c
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# `col 01`$`col 03` <chr>, $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 50)
Output
Expand All @@ -782,8 +777,7 @@
3 3.23 c c
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# `col 01`$`col 03` <chr>, $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 51)
Output
Expand All @@ -798,8 +792,7 @@
3 3.23 c c
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# `col 01`$`col 03` <chr>, $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 52)
Output
Expand All @@ -814,8 +807,7 @@
3 3.23 c c
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# `col 01`$`col 03` <chr>, $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 53)
Output
Expand All @@ -830,8 +822,7 @@
3 3.23 c c
<tbl_format_footer(setup)>
# ... with 2 more variables:
# `col 01`$`col 03` <chr>,
# `col 01`$`col 04` <tbl[,2]>
# `col 01`$`col 03` <chr>, $`col 04` <tbl[,2]>
Code
tbl_format_setup(x, width = 54)
Output
Expand Down

0 comments on commit 5508951

Please sign in to comment.