1- print_text_table_with_huxtable <- function (df , title = NULL , footnote = NULL ,
2- heatmap_columns = NULL , hilite_rows = NULL ,
3- styler = huxtable_text_table_default_styler , ... )
4- {
5- # ## build the huxtable
6- tt <- huxtable :: as_hux(df )
71
8- if (length(footnote )) tt <- huxtable :: add_footnote(tt , footnote )
9- if (length(title )) tt <- huxtable :: set_caption(tt , title )
10-
11-
12- if (length(styler )) tt <- styler(tt , heatmap_columns = heatmap_columns , hilite_rows = hilite_rows )
13-
14- # now print
15- lines <- huxtable :: to_screen(tt , max_width = Inf , colnames = FALSE )
16- cat(lines , sep = ' \n ' )
17-
18- invisible (tt )
19- }
20-
21- huxtable_text_table_default_styler <- function (tt ,
22- heatmap_columns = NULL , heatmap_colorspace = c(' green' , ' red' ),
23- hilite_rows = NULL , hilite_bg = ' red'
24- , fg = ' black' , bg = ' #f7f7f7' )
25- {
26- # ## set the title position: top
27- huxtable :: caption_pos(tt ) <- ' top'
28- # ## make the header line BOLD
29- tt <- huxtable :: set_bold(tt , 1 , huxtable :: everywhere , TRUE )
30-
31- # ## colors
32- tt <- huxtable :: set_background_color(tt , 1 , huxtable :: everywhere , bg )
33- tt <- huxtable :: set_text_color(tt , 1 , huxtable :: everywhere , fg )
34-
35- # ## hilite
36- tt <- huxtable :: set_background_color(tt , hilite_rows + 1 , huxtable :: everywhere , hilite_bg )
37-
38- # ## heatmap
39- if (length(heatmap_columns ))
40- for (col in heatmap_columns )
41- tt <- huxtable :: map_background_color(tt , huxtable :: everywhere , col , huxtable :: by_colorspace(heatmap_colorspace ))
42-
43-
44- # ## borders
45- tt <- huxtable :: set_bottom_border(tt , 1 , huxtable :: everywhere , 1 )
46- tt <- huxtable :: set_left_border(tt , 1 )
47- tt <- huxtable :: set_outer_borders(tt , 1 )
48- tt <- huxtable :: set_bottom_border(tt , huxtable :: final(1 ), huxtable :: everywhere , 1 )
49-
50- # ## alignment
51- tt <- huxtable :: set_align(tt , value = ' left' )
52-
53- tt
54- }
55-
56- print_text_table_with_base <- function (df , ... ) {
57- print(df )
58- invisible ()
59- }
60-
61- print_text_table <- function (df , ... ) {
62- if (! requireNamespace(" huxtable" , quietly = TRUE )) {
63- print_text_table_with_base(df , ... )
64- } else {
65- print_text_table_with_huxtable(df , ... )
66- }
67- invisible ()
68- }
2+ print_text_table <- function (df , title = NULL , header_style = " bold" , border_style = " double-single" , ... ) {
3+ if (length(title )) cli :: cli_h1(title )
4+ ct <- cli_table(df , header_style = header_style , border_style = border_style , ... )
5+ cat(ct , sep = " \n " )
6+ }
0 commit comments