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,012,155
cohort2 number subjects - N 6,493,812
cohort1 age - Mean (SD) 29.15 (8.53)
cohort2 age - Mean (SD) 86.40 (3.18)
cohort1 Medications Amoxiciline N% 42,519 (81.28)
cohort2 Medications Amoxiciline N% 82,087 (40.21)
cohort1 Medications Ibuprofen N% 55,531 (87.86)
cohort2 Medications Ibuprofen N% 4,886 (69.78)
age_group &&& sex; <40 &&& Male
1 mock cohort_name cohort1 number subjects - N 4,249,537
cohort2 number subjects - N 2,602,081
cohort1 age - Mean (SD) 90.69 (8.87)
cohort2 age - Mean (SD) 10.65 (1.35)
cohort1 Medications Amoxiciline N% 83,123 (30.24)
cohort2 Medications Amoxiciline N% 34,727 (14.42)
cohort1 Medications Ibuprofen N% 4,483 (38.98)
cohort2 Medications Ibuprofen N% 28,574 (98.88)
age_group &&& sex; >=40 &&& Male
1 mock cohort_name cohort1 number subjects - N 2,110,110
cohort2 number subjects - N 3,232,491
cohort1 age - Mean (SD) 17.82 (4.57)
cohort2 age - Mean (SD) 74.89 (9.43)
cohort1 Medications Amoxiciline N% 18,203 (8.40)
cohort2 Medications Amoxiciline N% 84,521 (8.47)
cohort1 Medications Ibuprofen N% 42,031 (19.38)
cohort2 Medications Ibuprofen N% 85,788 (42.37)
age_group &&& sex; <40 &&& Female
1 mock cohort_name cohort1 number subjects - N 481,151
cohort2 number subjects - N 6,612,474
cohort1 age - Mean (SD) 91.40 (1.05)
cohort2 age - Mean (SD) 58.27 (5.98)
cohort1 Medications Amoxiciline N% 56,066 (39.76)
cohort2 Medications Amoxiciline N% 80,786 (85.10)
cohort1 Medications Ibuprofen N% 73,966 (18.56)
cohort2 Medications Ibuprofen N% 55,640 (52.70)
age_group &&& sex; >=40 &&& Female
1 mock cohort_name cohort1 number subjects - N 4,739,725
cohort2 number subjects - N 2,370,871
cohort1 age - Mean (SD) 58.30 (2.80)
cohort2 age - Mean (SD) 51.23 (7.25)
cohort1 Medications Amoxiciline N% 63,604 (4.93)
cohort2 Medications Amoxiciline N% 70,355 (48.39)
cohort1 Medications Ibuprofen N% 51,352 (86.25)
cohort2 Medications Ibuprofen N% 45,659 (51.15)
sex; Male
1 mock cohort_name cohort1 number subjects - N 9,722,978
cohort2 number subjects - N 8,282,743
cohort1 age - Mean (SD) 40.14 (6.56)
cohort2 age - Mean (SD) 29.35 (3.14)
cohort1 Medications Amoxiciline N% 22,084 (37.14)
cohort2 Medications Amoxiciline N% 13,769 (85.68)
cohort1 Medications Ibuprofen N% 15,981 (55.44)
cohort2 Medications Ibuprofen N% 63,828 (64.55)
sex; Female
1 mock cohort_name cohort1 number subjects - N 921,884
cohort2 number subjects - N 6,662,380
cohort1 age - Mean (SD) 54.66 (3.76)
cohort2 age - Mean (SD) 99.11 (6.79)
cohort1 Medications Amoxiciline N% 66,826 (28.75)
cohort2 Medications Amoxiciline N% 16,167 (66.33)
cohort1 Medications Ibuprofen N% 64,206 (67.12)
cohort2 Medications Ibuprofen N% 97,123 (64.00)
age_group; <40
1 mock cohort_name cohort1 number subjects - N 2,069,944
cohort2 number subjects - N 5,409,234
cohort1 age - Mean (SD) 33.55 (8.25)
cohort2 age - Mean (SD) 91.82 (2.68)
cohort1 Medications Amoxiciline N% 91,820 (52.93)
cohort2 Medications Amoxiciline N% 27,483 (75.63)
cohort1 Medications Ibuprofen N% 83,243 (22.69)
cohort2 Medications Ibuprofen N% 76,411 (54.85)
age_group; >=40
1 mock cohort_name cohort1 number subjects - N 2,437,146
cohort2 number subjects - N 1,210,301
cohort1 age - Mean (SD) 91.09 (6.83)
cohort2 age - Mean (SD) 99.51 (2.28)
cohort1 Medications Amoxiciline N% 9,427 (1.49)
cohort2 Medications Amoxiciline N% 88,254 (57.99)
cohort1 Medications Ibuprofen N% 54,962 (0.52)
cohort2 Medications Ibuprofen N% 12,776 (48.84)