Transform an rtable to a list of matrices which can be used for outputting
Source: R/tt_toString.R
matrix_form-VTableTree-method.RdAlthough rtables are represented as a tree data structure when outputting the table to ASCII or HTML
it is useful to map the rtable to an in-between state with the formatted cells in a matrix form.
Usage
# S4 method for class 'VTableTree'
matrix_form(
obj,
indent_rownames = FALSE,
expand_newlines = TRUE,
indent_size = 2,
fontspec = NULL,
col_gap = 3L,
round_type = obj_round_type(obj)
)Arguments
- obj
(
ANY)
the object for the accessor to access or modify.- indent_rownames
(
flag)
ifTRUE, the column with the row names in thestringsmatrix of the output has indented row names (strings pre-fixed).- expand_newlines
(
flag)
whether the matrix form generated should expand rows whose values contain newlines into multiple 'physical' rows (as they will appear when rendered into ASCII). Defaults toTRUE.- indent_size
(
numeric(1))
number of spaces to use per indent level. Defaults to 2.- fontspec
(
font_spec)
The font that should be used by default when rendering thisMatrixPrintFormobject, or NULL (the default).- col_gap
(
numeric(1))]
The number of spaces (in the font specified byfontspec) that should be placed between columns when the table is rendered directly to text (e.g., bytoStringorexport_as_txt). Defaults to3.- round_type
(
"iec"(default),"iec_mod"or"sas")
the type of rounding to perform. Seeformatters::format_value()for details.
Value
A list with the following elements:
stringsThe content, as it should be printed, of the top-left material, column headers, row labels, and cell values of
tt.spansThe column-span information for each print-string in the
stringsmatrix.alignsThe text alignment for each print-string in the
stringsmatrix.displayWhether each print-string in the strings matrix should be printed.
row_infoThe
data.framegenerated bymake_row_df.
With an additional nrow_header attribute indicating the number of pseudo "rows" that the column structure defines.
Details
The strings in the return object are defined as follows: row labels are those determined by make_row_df and cell
values are determined using get_formatted_cells. (Column labels are calculated using a non-exported internal
function.
Examples
library(dplyr)
iris2 <- iris %>%
group_by(Species) %>%
mutate(group = as.factor(rep_len(c("a", "b"), length.out = n()))) %>%
ungroup()
lyt <- basic_table() %>%
split_cols_by("Species") %>%
split_cols_by("group") %>%
analyze(c("Sepal.Length", "Petal.Width"),
afun = list_wrap_x(summary), format = "xx.xx"
)
lyt
#> A Pre-data Table Layout
#>
#> Column-Split Structure:
#> Species (lvls) -> group (lvls)
#>
#> Row-Split Structure:
#> Sepal.Length:Petal.Width (** multivar analysis **)
#>
tbl <- build_table(lyt, iris2)
matrix_form(tbl)
#> $strings
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] "" "setosa" "setosa" "versicolor" "versicolor" "virginica"
#> [2,] "" "a" "b" "a" "b" "a"
#> [3,] "Sepal.Length" "" "" "" "" ""
#> [4,] "Min." "4.40" "4.30" "5.00" "4.90" "4.90"
#> [5,] "1st Qu." "4.80" "4.80" "5.60" "5.60" "6.20"
#> [6,] "Median" "5.00" "5.00" "5.90" "5.90" "6.50"
#> [7,] "Mean" "5.02" "4.99" "5.99" "5.88" "6.50"
#> [8,] "3rd Qu." "5.30" "5.10" "6.40" "6.10" "6.70"
#> [9,] "Max." "5.80" "5.70" "7.00" "6.70" "7.70"
#> [10,] "Petal.Width" "" "" "" "" ""
#> [11,] "Min." "0.10" "0.10" "1.00" "1.00" "1.40"
#> [12,] "1st Qu." "0.20" "0.20" "1.20" "1.20" "1.90"
#> [13,] "Median" "0.20" "0.20" "1.30" "1.30" "2.10"
#> [14,] "Mean" "0.23" "0.26" "1.35" "1.30" "2.08"
#> [15,] "3rd Qu." "0.20" "0.30" "1.50" "1.40" "2.30"
#> [16,] "Max." "0.40" "0.60" "1.80" "1.70" "2.50"
#> [,7]
#> [1,] "virginica"
#> [2,] "b"
#> [3,] ""
#> [4,] "5.60"
#> [5,] "6.30"
#> [6,] "6.50"
#> [7,] "6.67"
#> [8,] "7.20"
#> [9,] "7.90"
#> [10,] ""
#> [11,] "1.50"
#> [12,] "1.80"
#> [13,] "2.00"
#> [14,] "1.98"
#> [15,] "2.20"
#> [16,] "2.50"
#>
#> $spans
#> setosa.a setosa.b versicolor.a versicolor.b virginica.a virginica.b
#> [1,] 1 2 2 2 2 2 2
#> [2,] 1 1 1 1 1 1 1
#> [3,] 1 1 1 1 1 1 1
#> [4,] 1 1 1 1 1 1 1
#> [5,] 1 1 1 1 1 1 1
#> [6,] 1 1 1 1 1 1 1
#> [7,] 1 1 1 1 1 1 1
#> [8,] 1 1 1 1 1 1 1
#> [9,] 1 1 1 1 1 1 1
#> [10,] 1 1 1 1 1 1 1
#> [11,] 1 1 1 1 1 1 1
#> [12,] 1 1 1 1 1 1 1
#> [13,] 1 1 1 1 1 1 1
#> [14,] 1 1 1 1 1 1 1
#> [15,] 1 1 1 1 1 1 1
#> [16,] 1 1 1 1 1 1 1
#>
#> $aligns
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] "left" "center" "center" "center" "center" "center" "center"
#> [2,] "left" "center" "center" "center" "center" "center" "center"
#> [3,] "left" "center" "center" "center" "center" "center" "center"
#> [4,] "left" "center" "center" "center" "center" "center" "center"
#> [5,] "left" "center" "center" "center" "center" "center" "center"
#> [6,] "left" "center" "center" "center" "center" "center" "center"
#> [7,] "left" "center" "center" "center" "center" "center" "center"
#> [8,] "left" "center" "center" "center" "center" "center" "center"
#> [9,] "left" "center" "center" "center" "center" "center" "center"
#> [10,] "left" "center" "center" "center" "center" "center" "center"
#> [11,] "left" "center" "center" "center" "center" "center" "center"
#> [12,] "left" "center" "center" "center" "center" "center" "center"
#> [13,] "left" "center" "center" "center" "center" "center" "center"
#> [14,] "left" "center" "center" "center" "center" "center" "center"
#> [15,] "left" "center" "center" "center" "center" "center" "center"
#> [16,] "left" "center" "center" "center" "center" "center" "center"
#>
#> $display
#> virginica.b1 virginica.b2 virginica.b3 virginica.b4 virginica.b5
#> [1,] TRUE TRUE FALSE TRUE FALSE TRUE
#> [2,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [3,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [4,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [5,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [6,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [7,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [8,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [9,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [10,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [11,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [12,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [13,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [14,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [15,] TRUE TRUE TRUE TRUE TRUE TRUE
#> [16,] TRUE TRUE TRUE TRUE TRUE TRUE
#> virginica.b6
#> [1,] FALSE
#> [2,] TRUE
#> [3,] TRUE
#> [4,] TRUE
#> [5,] TRUE
#> [6,] TRUE
#> [7,] TRUE
#> [8,] TRUE
#> [9,] TRUE
#> [10,] TRUE
#> [11,] TRUE
#> [12,] TRUE
#> [13,] TRUE
#> [14,] TRUE
#> [15,] TRUE
#> [16,] TRUE
#>
#> $formats
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] "" "" "" "" "" "" ""
#> [2,] "" "" "" "" "" "" ""
#> [3,] "" "-" "-" "-" "-" "-" "-"
#> [4,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [5,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [6,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [7,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [8,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [9,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [10,] "" "-" "-" "-" "-" "-" "-"
#> [11,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [12,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [13,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [14,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [15,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#> [16,] "" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx" "xx.xx"
#>
#> $row_info
#> label name abs_rownumber path pos_in_siblings
#> 1 Sepal.Length Sepal.Length 1 ma_Sepal.... NA
#> 2 Min. Min. 2 ma_Sepal.... 1
#> 3 1st Qu. 1st Qu. 3 ma_Sepal.... 2
#> 4 Median Median 4 ma_Sepal.... 3
#> 5 Mean Mean 5 ma_Sepal.... 4
#> 6 3rd Qu. 3rd Qu. 6 ma_Sepal.... 5
#> 7 Max. Max. 7 ma_Sepal.... 6
#> 8 Petal.Width Petal.Width 8 ma_Sepal.... NA
#> 9 Min. Min. 9 ma_Sepal.... 1
#> 10 1st Qu. 1st Qu. 10 ma_Sepal.... 2
#> 11 Median Median 11 ma_Sepal.... 3
#> 12 Mean Mean 12 ma_Sepal.... 4
#> 13 3rd Qu. 3rd Qu. 13 ma_Sepal.... 5
#> 14 Max. Max. 14 ma_Sepal.... 6
#> n_siblings self_extent par_extent reprint_inds node_class indent nrowrefs
#> 1 NA 1 0 LabelRow 0 0
#> 2 6 1 1 1 DataRow 0 0
#> 3 6 1 1 1 DataRow 0 0
#> 4 6 1 1 1 DataRow 0 0
#> 5 6 1 1 1 DataRow 0 0
#> 6 6 1 1 1 DataRow 0 0
#> 7 6 1 1 1 DataRow 0 0
#> 8 NA 1 0 LabelRow 0 0
#> 9 6 1 1 8 DataRow 0 0
#> 10 6 1 1 8 DataRow 0 0
#> 11 6 1 1 8 DataRow 0 0
#> 12 6 1 1 8 DataRow 0 0
#> 13 6 1 1 8 DataRow 0 0
#> 14 6 1 1 8 DataRow 0 0
#> ncellrefs nreflines force_page page_title trailing_sep sect_div_from_path
#> 1 0 0 FALSE <NA> <NA> NA
#> 2 0 0 FALSE <NA> <NA> ma_Sepal....
#> 3 0 0 FALSE <NA> <NA> ma_Sepal....
#> 4 0 0 FALSE <NA> <NA> ma_Sepal....
#> 5 0 0 FALSE <NA> <NA> ma_Sepal....
#> 6 0 0 FALSE <NA> <NA> ma_Sepal....
#> 7 0 0 FALSE <NA> <NA> ma_Sepal....
#> 8 0 0 FALSE <NA> <NA> NA
#> 9 0 0 FALSE <NA> <NA> ma_Sepal....
#> 10 0 0 FALSE <NA> <NA> ma_Sepal....
#> 11 0 0 FALSE <NA> <NA> ma_Sepal....
#> 12 0 0 FALSE <NA> <NA> ma_Sepal....
#> 13 0 0 FALSE <NA> <NA> ma_Sepal....
#> 14 0 0 FALSE <NA> <NA> ma_Sepal....
#> self_section_div
#> 1 <NA>
#> 2 <NA>
#> 3 <NA>
#> 4 <NA>
#> 5 <NA>
#> 6 <NA>
#> 7 <NA>
#> 8 <NA>
#> 9 <NA>
#> 10 <NA>
#> 11 <NA>
#> 12 <NA>
#> 13 <NA>
#> 14 <NA>
#>
#> $line_grouping
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#>
#> $ref_footnotes
#> character(0)
#>
#> $main_title
#> [1] ""
#>
#> $subtitles
#> character(0)
#>
#> $page_titles
#> character(0)
#>
#> $main_footer
#> character(0)
#>
#> $prov_footer
#> character(0)
#>
#> $header_section_div
#> [1] NA
#>
#> $horizontal_sep
#> [1] "—"
#>
#> $col_gap
#> [1] 3
#>
#> $listing_keycols
#> NULL
#>
#> $table_inset
#> [1] 0
#>
#> $has_topleft
#> [1] TRUE
#>
#> $indent_size
#> [1] 2
#>
#> $col_widths
#> [1] 12 4 4 5 5 5 4
#>
#> $fontspec
#> NULL
#>
#> $num_rep_cols
#> [1] 0
#>
#> $round_type
#> [1] "iec"
#>
#> $ref_fnote_df
#> [1] row_path col_path row col symbol ref_index msg
#> [8] nlines
#> <0 rows> (or 0-length row.names)
#>
#> $col_info
#> label name abs_rownumber path pos_in_siblings n_siblings self_extent
#> 1 1 1 1 Species,.... 0 0 4
#> 2 2 2 2 Species,.... 0 0 4
#> 3 3 3 3 Species,.... 0 0 5
#> 4 4 4 4 Species,.... 0 0 5
#> 5 5 5 5 Species,.... 0 0 5
#> 6 6 6 6 Species,.... 0 0 4
#> par_extent reprint_inds node_class indent nrowrefs ncellrefs nreflines
#> 1 0 stuff 0 0 0 0
#> 2 0 stuff 0 0 0 0
#> 3 0 stuff 0 0 0 0
#> 4 0 stuff 0 0 0 0
#> 5 0 stuff 0 0 0 0
#> 6 0 stuff 0 0 0 0
#> force_page page_title trailing_sep ref_info_df
#> 1 FALSE <NA> <NA>
#> 2 FALSE <NA> <NA>
#> 3 FALSE <NA> <NA>
#> 4 FALSE <NA> <NA>
#> 5 FALSE <NA> <NA>
#> 6 FALSE <NA> <NA>
#>
#> attr(,"nrow_header")
#> [1] 2
#> attr(,"ncols")
#> [1] 6
#> attr(,"class")
#> [1] "MatrixPrintForm" "list"