Collection of utilities to extract data.frame objects from TableTree objects.
Usage
as_result_df(
tt,
spec = NULL,
data_format = c("full_precision", "strings", "numeric"),
make_ard = FALSE,
expand_colnames = FALSE,
keep_label_rows = FALSE,
add_tbl_name_split = FALSE,
simplify = FALSE,
verbose = FALSE,
...
)
path_enriched_df(tt, path_fun = collapse_path, value_fun = collapse_values)Arguments
- tt
(
TableTreeor related class)
aTableTreeobject representing a populated table.- spec
(
function)
function that generates the result data frame from a table (TableTree). It defaults toNULL, for standard processing.- data_format
(
string)
the format of the data in the result data frame. It can be one value between"full_precision"(default),"strings", and"numeric". The last two values show the numeric data with the visible precision.- make_ard
(
flag)
whenTRUE, the result data frame will have only one statistic per row.- expand_colnames
(
flag)
whenTRUE, the result data frame will have expanded column names above the usual output. This is useful when the result data frame is used for further processing.- keep_label_rows
(
flag)
whenTRUE, the result data frame will have all labels as they appear in the final table.- add_tbl_name_split
(
flag)
whenTRUEand when the table has more than oneanalyze(table_names = "<diff_names>"), the table names will be present as a group split named"<analysis_spl_tbl_name>".- simplify
(
flag)
whenTRUE, the result data frame will have only visible labels and result columns. Consider showing also label rows withkeep_label_rows = TRUE. This output can be used again to create aTableTreeobject withdf_to_tt().- verbose
(
flag)
whenTRUE, the function will print additional information fordata_format != "full_precision".- ...
additional arguments passed to spec-specific result data frame function (
spec). When usingmake_ard = TRUE, it is possible to turn off the extraction of the exact string decimals printed by the table withadd_tbl_str_decimals = FALSE.- path_fun
(
function)
function to transform paths into single-string row/column names.- value_fun
(
function)
function to transform cell values into cells of adata.frame. Defaults tocollapse_values, which creates strings where multi-valued cells are collapsed together, separated by|.
Value
as_result_dfreturns a resultdata.frame.
path_enriched_df()returns adata.frameoftt's cell values (processed byvalue_fun, with columns named by the full column paths (processed bypath_funand an additionalrow_pathcolumn with the row paths (processed bypath_fun).
See also
df_to_tt() when using simplify = TRUE and formatters::make_row_df() to have a
comprehensive view of the hierarchical structure of the rows.
Examples
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("STRATA1") %>%
analyze(c("AGE", "BMRKR2"))
tbl <- build_table(lyt, ex_adsl)
as_result_df(tbl, simplify = TRUE)
#> label_name A: Drug X B: Placebo C: Combination
#> 1 Mean 33.07895 35.11364 34.225
#> 2 LOW 12 16 14
#> 3 MEDIUM 10 17 13
#> 4 HIGH 16 11 13
#> 5 Mean 33.85106 36 36.32558
#> 6 LOW 19 13 10
#> 7 MEDIUM 13 22 16
#> 8 HIGH 15 10 17
#> 9 Mean 34.22449 35.17778 35.63265
#> 10 LOW 19 16 16
#> 11 MEDIUM 14 17 13
#> 12 HIGH 16 12 20
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
analyze(c("AGE", "BMRKR2"))
tbl <- build_table(lyt, ex_adsl)
path_enriched_df(tbl)
#> row_path ARM|A: Drug X ARM|B: Placebo ARM|C: Combination
#> 1 ma_AGE_BMRKR2|AGE|Mean 33.76866 35.43284 35.43182
#> 2 ma_AGE_BMRKR2|BMRKR2|LOW 50.00000 45.00000 40.00000
#> 3 ma_AGE_BMRKR2|BMRKR2|MEDIUM 37.00000 56.00000 42.00000
#> 4 ma_AGE_BMRKR2|BMRKR2|HIGH 47.00000 33.00000 50.00000