If the default data output in a tibble doesn’t work for you, the decor_() family of functions allows overriding it on a column-by-column basis.
In the first example, the default number of significant figures is insufficient to show the difference between the numbers:
tibble(a = 2:6 + 1:5 * 1e-6)
#> # A tibble: 5 x 1
#> a
#> <dbl>
#> 1 2.00
#> 2 3.00
#> 3 4.00
#> 4 5.00
#> # ... with 1 more rowOverride the display by using decor_num() to indicate the number of significant digits to use for this column.
decorated_num <- tibble(
a = decor_num(2:6 + 1:5 * 1e-6, 7),
b = 1:5
)
decorated_num
#> # A tibble: 5 x 2
#> a b
#> <dbl> <int>
#> 1 2.000001 1
#> 2 3.000002 2
#> 3 4.000003 3
#> 4 5.000004 4
#> # ... with 1 more rowThe decoration survives base R subsetting, arithmetic operations, and most dplyr single-table verbs and joins:
head(decorated_num, 2)
#> # A tibble: 2 x 2
#> a b
#> <dbl> <int>
#> 1 2.000001 1
#> 2 3.000002 2
decorated_num[2:3, ]
#> # A tibble: 2 x 2
#> a b
#> <dbl> <int>
#> 1 3.000002 2
#> 2 4.000003 3
decorated_num %>%
filter(a < 4) %>%
arrange(-a) %>%
left_join(tibble(b = 2:4, c = letters[2:4])) %>%
select(-b) %>%
mutate(aa = a + 1 * 2)
#> Joining, by = "b"
#> # A tibble: 2 x 3
#> a c aa
#> <dbl> <chr> <dbl>
#> 1 3.000002 b 5.000002
#> 2 2.000001 <NA> 4.000001So far, decorations have been defined only for numbers and characters, here you can specify the minimum of characters to be shown if the strings need truncation. Compare the following outputs:
id <- "1234567890123456789012345678901234567890"
tibble(
id = id,
an_astonishingly_wide_column_name_to_show_truncation = 1,
yet_another_extemely_wide_column = 2,
give_me_more_of_these = 3
)
#> # A tibble: 1 x 4
#> id an_astonishingly_wide_… yet_another_extem… give_me_more_of…
#> <chr> <dbl> <dbl> <dbl>
#> 1 12345678901… 1 2 3
tibble(
id = decor_chr(id, 40),
an_astonishingly_wide_column_name_to_show_truncation = 1,
yet_another_extemely_wide_column = 2,
give_me_more_of_these = 3
)
#> # A tibble: 1 x 4
#> id an_astonishingly_wide_column_n…
#> <chr> <dbl>
#> 1 1234567890123456789012345678901234567890 1
#> # ... with 2 more variables: yet_another_extemely_wide_column <dbl>,
#> # give_me_more_of_these <dbl>Column decorations offer a flexible and extensible way of defining how a column should be printed. Expect more decorations to be added to tibble and contributed from other packages!
TODO: Describe how to implement your own decoration class.