Helper function to use mostly within tests. with_spacesparameter allows
to test not only for content but also indentation and table structure.
print_txt_to_copy instead facilitate the testing development by returning a well
formatted text that needs only to be copied and pasted in the expected output.
Usage
to_string_matrix(
x,
widths = NULL,
max_width = NULL,
hsep = formatters::default_hsep(),
with_spaces = TRUE,
print_txt_to_copy = FALSE
)Arguments
- x
rtablestable.- widths
numeric (or
NULL). (proposed) widths for the columns ofx. The expected length of this numeric vector can be retrieved withncol() + 1as the column of row names must also be considered.- max_width
integer(1), character(1) or
NULL. Width that title and footer (including footnotes) materials should be word-wrapped to. IfNULL, it is set to the current print width of the session (getOption("width")). If set to"auto", the width of the table (plus any table inset) is used. Ignored completely iftf_wrapisFALSE.- hsep
character(1). Characters to repeat to create header/body separator line. If
NULL, the object value will be used. If" ", an empty separator will be printed. Checkdefault_hsep()for more information.- with_spaces
(
logical)
should the tested table keep the indentation and other relevant spaces?- print_txt_to_copy
(
logical)
utility to have a way to copy the input table directly into the expected variable instead of copying it too manually.
Value
A matrix of strings. If print_txt_to_copy = TRUE the well formatted printout of the
table will be printed to console, ready to be copied as a expected value.
Examples
tbl <- basic_table() %>%
split_rows_by("SEX") %>%
split_cols_by("ARM") %>%
analyze("AGE") %>%
build_table(tern_ex_adsl)
to_string_matrix(tbl, widths = ceiling(propose_column_widths(tbl) / 2))
#> [1] " A: " " Drug B: Pl C: Comb"
#> [3] " X acebo ination" "—————————————————————————————"
#> [5] "F " " M 33.68 35.98 36.02 "
#> [7] " e " " a "
#> [9] " n " "M "
#> [11] " M 34.70 35.68 36.28 " " e "
#> [13] " a " " n "
