Skip to contents

[Experimental] This function combines the functionalities of formatEstimateValue(), formatEstimateName(), formatHeader(), and formatTable() into a single function. While it does not require the input table to be a <summarised_result>, it does expect specific fields to apply some formatting functionalities.

Usage

visTable(
  result,
  estimateName = character(),
  header = character(),
  groupColumn = character(),
  rename = character(),
  type = "gt",
  hide = character(),
  .options = list()
)

Arguments

result

A table to format.

estimateName

A named list of estimate names to join, sorted by computation order. Use <...> to indicate estimate names. This argument requires that the table has estimate_name and estimate_value columns.

header

A vector specifying the elements to include in the header. The order of elements matters, with the first being the topmost header. The vector elements can be column names or labels for overall headers. The table must contain an estimate_value column to pivot the headers.

groupColumn

Columns to use as group labels. By default, the name of the new group will be the tidy* column names separated by ";". To specify a custom group name, use a named list such as: list("newGroupName" = c("variable_name", "variable_level")).

*tidy: The tidy format applied to column names replaces "_" with a space and converts them to sentence case. Use rename to customize specific column names.

rename

A named vector to customize column names, e.g., c("Database name" = "cdm_name"). The function will rename all column names not specified here into a tidy* format.

type

The desired format of the output table. See tableType() for allowed options.

hide

Columns to drop from the output table.

.options

A named list with additional formatting options. visOmopResults::tableOptions() shows allowed arguments and their default values.

Value

A tibble, gt, or flextable object.

Examples

result <- mockSummarisedResult()
result |>
  visTable(
    estimateName = c("N%" = "<count> (<percentage>)",
                     "N" = "<count>",
                     "Mean (SD)" = "<mean> (<sd>)"),
    header = c("Estimate"),
    rename = c("Database name" = "cdm_name"),
    groupColumn = c("strata_name", "strata_level"),
    hide = c("additional_name", "additional_level", "estimate_type", "result_type")
  )
Result id Database name Group name Group level Variable name Variable level Estimate name Estimate
overall; overall
1 mock cohort_name cohort1 number subjects - N 2,202,471
cohort2 number subjects - N 4,513,757
cohort1 age - Mean (SD) 44.81 (7.83)
cohort2 age - Mean (SD) 26.89 (7.36)
cohort1 Medications Amoxiciline N% 62,237 (92.84)
cohort2 Medications Amoxiciline N% 33,863 (63.98)
cohort1 Medications Ibuprofen N% 24,332 (61.44)
cohort2 Medications Ibuprofen N% 16,482 (1.81)
age_group &&& sex; <40 &&& Male
1 mock cohort_name cohort1 number subjects - N 371,822
cohort2 number subjects - N 7,942,700
cohort1 age - Mean (SD) 82.39 (6.22)
cohort2 age - Mean (SD) 88.35 (9.41)
cohort1 Medications Amoxiciline N% 55,533 (41.34)
cohort2 Medications Amoxiciline N% 76,968 (88.25)
cohort1 Medications Ibuprofen N% 51,505 (19.24)
cohort2 Medications Ibuprofen N% 18,098 (38.20)
age_group &&& sex; >=40 &&& Male
1 mock cohort_name cohort1 number subjects - N 6,980,541
cohort2 number subjects - N 8,246,223
cohort1 age - Mean (SD) 96.94 (8.66)
cohort2 age - Mean (SD) 67.06 (8.61)
cohort1 Medications Amoxiciline N% 96,107 (13.10)
cohort2 Medications Amoxiciline N% 30,134 (94.62)
cohort1 Medications Ibuprofen N% 86,319 (7.18)
cohort2 Medications Ibuprofen N% 99,645 (51.36)
age_group &&& sex; <40 &&& Female
1 mock cohort_name cohort1 number subjects - N 1,498,340
cohort2 number subjects - N 2,090,516
cohort1 age - Mean (SD) 29.54 (9.20)
cohort2 age - Mean (SD) 7.43 (3.64)
cohort1 Medications Amoxiciline N% 91,564 (6.12)
cohort2 Medications Amoxiciline N% 62,964 (70.94)
cohort1 Medications Ibuprofen N% 4,056 (30.62)
cohort2 Medications Ibuprofen N% 64,511 (4.72)
age_group &&& sex; >=40 &&& Female
1 mock cohort_name cohort1 number subjects - N 5,424,376
cohort2 number subjects - N 1,682,065
cohort1 age - Mean (SD) 23.27 (3.25)
cohort2 age - Mean (SD) 68.53 (9.13)
cohort1 Medications Amoxiciline N% 60,328 (88.61)
cohort2 Medications Amoxiciline N% 80,250 (92.36)
cohort1 Medications Ibuprofen N% 46,003 (17.46)
cohort2 Medications Ibuprofen N% 91,810 (80.31)
sex; Male
1 mock cohort_name cohort1 number subjects - N 7,967,724
cohort2 number subjects - N 9,802,742
cohort1 age - Mean (SD) 32.55 (9.16)
cohort2 age - Mean (SD) 60.08 (7.53)
cohort1 Medications Amoxiciline N% 31,155 (59.22)
cohort2 Medications Amoxiciline N% 54,224 (1.62)
cohort1 Medications Ibuprofen N% 16,600 (88.78)
cohort2 Medications Ibuprofen N% 79,507 (63.41)
sex; Female
1 mock cohort_name cohort1 number subjects - N 7,196,247
cohort2 number subjects - N 6,006,700
cohort1 age - Mean (SD) 10.04 (0.81)
cohort2 age - Mean (SD) 70.61 (6.41)
cohort1 Medications Amoxiciline N% 55,515 (72.24)
cohort2 Medications Amoxiciline N% 63,100 (17.15)
cohort1 Medications Ibuprofen N% 91,538 (49.78)
cohort2 Medications Ibuprofen N% 91,310 (77.13)
age_group; <40
1 mock cohort_name cohort1 number subjects - N 7,281,897
cohort2 number subjects - N 1,516,763
cohort1 age - Mean (SD) 33.02 (8.56)
cohort2 age - Mean (SD) 46.82 (7.95)
cohort1 Medications Amoxiciline N% 93,760 (51.24)
cohort2 Medications Amoxiciline N% 18,979 (21.40)
cohort1 Medications Ibuprofen N% 40,942 (69.39)
cohort2 Medications Ibuprofen N% 39,056 (50.18)
age_group; >=40
1 mock cohort_name cohort1 number subjects - N 478,162
cohort2 number subjects - N 2,927,387
cohort1 age - Mean (SD) 19.26 (3.05)
cohort2 age - Mean (SD) 1.10 (9.85)
cohort1 Medications Amoxiciline N% 36,504 (29.61)
cohort2 Medications Amoxiciline N% 20,345 (84.51)
cohort1 Medications Ibuprofen N% 64,053 (87.42)
cohort2 Medications Ibuprofen N% 35,740 (71.13)