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 7,299,699
cohort2 number subjects - N 9,711,406
cohort1 age - Mean (SD) 43.56 (1.11)
cohort2 age - Mean (SD) 96.10 (1.61)
cohort1 Medications Amoxiciline N% 99,345 (40.69)
cohort2 Medications Amoxiciline N% 85,121 (49.19)
cohort1 Medications Ibuprofen N% 15,376 (2.15)
cohort2 Medications Ibuprofen N% 2,507 (65.38)
age_group &&& sex; <40 &&& Male
1 mock cohort_name cohort1 number subjects - N 8,941,871
cohort2 number subjects - N 2,327,210
cohort1 age - Mean (SD) 28.93 (9.38)
cohort2 age - Mean (SD) 27.06 (1.76)
cohort1 Medications Amoxiciline N% 62,749 (1.94)
cohort2 Medications Amoxiciline N% 48,000 (44.66)
cohort1 Medications Ibuprofen N% 94,473 (25.28)
cohort2 Medications Ibuprofen N% 75,234 (35.33)
age_group &&& sex; >=40 &&& Male
1 mock cohort_name cohort1 number subjects - N 2,203,064
cohort2 number subjects - N 8,674,180
cohort1 age - Mean (SD) 63.76 (8.46)
cohort2 age - Mean (SD) 73.06 (1.98)
cohort1 Medications Amoxiciline N% 1,463 (5.02)
cohort2 Medications Amoxiciline N% 53,727 (69.02)
cohort1 Medications Ibuprofen N% 51,947 (65.67)
cohort2 Medications Ibuprofen N% 73,207 (59.66)
age_group &&& sex; <40 &&& Female
1 mock cohort_name cohort1 number subjects - N 2,915,964
cohort2 number subjects - N 1,107,617
cohort1 age - Mean (SD) 26.45 (5.71)
cohort2 age - Mean (SD) 13.42 (3.58)
cohort1 Medications Amoxiciline N% 20,518 (70.23)
cohort2 Medications Amoxiciline N% 66,164 (84.27)
cohort1 Medications Ibuprofen N% 45,563 (78.91)
cohort2 Medications Ibuprofen N% 40,911 (72.77)
age_group &&& sex; >=40 &&& Female
1 mock cohort_name cohort1 number subjects - N 8,128,987
cohort2 number subjects - N 8,014,918
cohort1 age - Mean (SD) 38.63 (6.79)
cohort2 age - Mean (SD) 4.84 (1.81)
cohort1 Medications Amoxiciline N% 66,308 (6.64)
cohort2 Medications Amoxiciline N% 30,085 (37.58)
cohort1 Medications Ibuprofen N% 22,009 (70.88)
cohort2 Medications Ibuprofen N% 63,086 (99.56)
sex; Male
1 mock cohort_name cohort1 number subjects - N 436,023
cohort2 number subjects - N 6,579,245
cohort1 age - Mean (SD) 61.92 (0.89)
cohort2 age - Mean (SD) 70.36 (5.61)
cohort1 Medications Amoxiciline N% 46,374 (3.61)
cohort2 Medications Amoxiciline N% 26,350 (98.49)
cohort1 Medications Ibuprofen N% 13,918 (6.46)
cohort2 Medications Ibuprofen N% 6,544 (49.81)
sex; Female
1 mock cohort_name cohort1 number subjects - N 5,052,717
cohort2 number subjects - N 6,520,543
cohort1 age - Mean (SD) 54.17 (7.85)
cohort2 age - Mean (SD) 14.72 (6.59)
cohort1 Medications Amoxiciline N% 36,035 (2.02)
cohort2 Medications Amoxiciline N% 30,505 (95.24)
cohort1 Medications Ibuprofen N% 21,616 (51.13)
cohort2 Medications Ibuprofen N% 14,869 (23.03)
age_group; <40
1 mock cohort_name cohort1 number subjects - N 2,416,559
cohort2 number subjects - N 2,263,226
cohort1 age - Mean (SD) 48.48 (2.27)
cohort2 age - Mean (SD) 76.92 (6.60)
cohort1 Medications Amoxiciline N% 68,937 (37.28)
cohort2 Medications Amoxiciline N% 87,496 (98.99)
cohort1 Medications Ibuprofen N% 40,568 (20.09)
cohort2 Medications Ibuprofen N% 27,970 (30.13)
age_group; >=40
1 mock cohort_name cohort1 number subjects - N 5,891,424
cohort2 number subjects - N 8,539,796
cohort1 age - Mean (SD) 76.43 (4.48)
cohort2 age - Mean (SD) 17.64 (0.02)
cohort1 Medications Amoxiciline N% 25,886 (22.57)
cohort2 Medications Amoxiciline N% 71,844 (44.31)
cohort1 Medications Ibuprofen N% 23,373 (81.41)
cohort2 Medications Ibuprofen N% 85,066 (72.05)