format functions

The format set of functions can be combined to format a summarised_result object (see R package omopgenerics) into a nice tibble, flextable or gt table to display in reports and shiny apps.

The functions formatEstimateValue(), formatEstimateName(), formatHeader(), and lastly gtTable() or fxTable() can be implemented in a pipeline to obtain the desired formatted table. Otherwise, these steps are implemented in the function visOmopTable().

Formatting functions in a pipeline

First, we load the relevant libraries and generate a summarised_result with mock results.

library(visOmopResults)
library(dplyr)
mock_sr <- mockSummarisedResult()
mock_sr |> glimpse()
#> Rows: 126
#> Columns: 13
#> $ result_id        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name         <chr> "mock", "mock", "mock", "mock", "mock", "mock", "mock…
#> $ group_name       <chr> "cohort_name", "cohort_name", "cohort_name", "cohort_…
#> $ group_level      <chr> "cohort1", "cohort1", "cohort1", "cohort1", "cohort1"…
#> $ strata_name      <chr> "overall", "age_group &&& sex", "age_group &&& sex", …
#> $ strata_level     <chr> "overall", "<40 &&& Male", ">=40 &&& Male", "<40 &&& …
#> $ variable_name    <chr> "number subjects", "number subjects", "number subject…
#> $ variable_level   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ estimate_name    <chr> "count", "count", "count", "count", "count", "count",…
#> $ estimate_type    <chr> "integer", "integer", "integer", "integer", "integer"…
#> $ estimate_value   <chr> "8826168", "1767348", "6631712", "6027918", "5296819"…
#> $ additional_name  <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…

1. formatEstimateValue()

This function provides tools to format the estimate_value column: choose number of decimals to display for each estimate_type or estimate_name (decimals), and change change the decimal and thousand/million separator mark (decimalMark and bigMark respectively)

By default, decimals of integer values are set to 0, numeric to 2, percentage to 1, and proportion to 3. The defaulted decimal mark is “.” while the thousand/million separator is “,”.

mock_sr <- mock_sr |> formatEstimateValue()
mock_sr |> glimpse()
#> Rows: 126
#> Columns: 13
#> $ result_id        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name         <chr> "mock", "mock", "mock", "mock", "mock", "mock", "mock…
#> $ group_name       <chr> "cohort_name", "cohort_name", "cohort_name", "cohort_…
#> $ group_level      <chr> "cohort1", "cohort1", "cohort1", "cohort1", "cohort1"…
#> $ strata_name      <chr> "overall", "age_group &&& sex", "age_group &&& sex", …
#> $ strata_level     <chr> "overall", "<40 &&& Male", ">=40 &&& Male", "<40 &&& …
#> $ variable_name    <chr> "number subjects", "number subjects", "number subject…
#> $ variable_level   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ estimate_name    <chr> "count", "count", "count", "count", "count", "count",…
#> $ estimate_type    <chr> "integer", "integer", "integer", "integer", "integer"…
#> $ estimate_value   <chr> "8,826,168", "1,767,348", "6,631,712", "6,027,918", "…
#> $ additional_name  <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…

If we want the same number of decimals for all the estimates, instead of a named vector the decimal argument can be a numeric pointing the number of decimals.

2. formatEstimateName()

We can customise estimate display by changing the estimate name and joining different estimates in the same row. For instance, we can display counts and percentages together as “N (%)”.

The estimateNameFormat is where combinations can be specified. Values from estimate_name’s column should be specified between <…>. The new estimate_name will be the names of this vector, or the value itself when it is not named.

mock_sr <- mock_sr |> 
  formatEstimateName(
    estimateNameFormat = c(
      "N (%)" = "<count> (<percentage>%)", 
      "N" = "<count>",
      "Mean (SD)" = "<mean> (<sd>)"
    ),
    keepNotFormatted = FALSE,
    useFormatOrder = FALSE
  )
mock_sr |> glimpse()
#> Rows: 72
#> Columns: 13
#> $ result_id        <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ cdm_name         <chr> "mock", "mock", "mock", "mock", "mock", "mock", "mock…
#> $ group_name       <chr> "cohort_name", "cohort_name", "cohort_name", "cohort_…
#> $ group_level      <chr> "cohort1", "cohort1", "cohort1", "cohort1", "cohort1"…
#> $ strata_name      <chr> "overall", "age_group &&& sex", "age_group &&& sex", …
#> $ strata_level     <chr> "overall", "<40 &&& Male", ">=40 &&& Male", "<40 &&& …
#> $ variable_name    <chr> "number subjects", "number subjects", "number subject…
#> $ variable_level   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ estimate_name    <chr> "N", "N", "N", "N", "N", "N", "N", "N", "N", "N", "N"…
#> $ estimate_type    <chr> "character", "character", "character", "character", "…
#> $ estimate_value   <chr> "8,826,168", "1,767,348", "6,631,712", "6,027,918", "…
#> $ additional_name  <chr> "overall", "overall", "overall", "overall", "overall"…
#> $ additional_level <chr> "overall", "overall", "overall", "overall", "overall"…

Additional input arguments are keepNotFormatted to specify whether not formatted rows should be returned or dropped. If useFormatOrder is TRUE, estimates will be presented in the order given in estimateNameFormat, if FALSE, the original order will be kept (where there is more than one estimate, the new position will be the first of the estimates being merged).

3. formatHeader()

This function helps to create a nice header for a flextable or gt table. For instance, instead of having a column specifying the group name and level, we might one them in the header.

Header keys: there are 3 different types of headers, identified with the keys “header”, “header_name”, and “header_level”.

For instance, we might want to pivot by “group_level” and have an upper header called “Names of the cohorts”. To do that we would proceed as follows:

mock_sr |>
  formatHeader(
    header = c("Names of the cohorts", "group_level"),
    delim = "\n",
    includeHeaderName = TRUE,
    includeHeaderKey = TRUE
  ) |>
  glimpse()
#> Rows: 36
#> Columns: 13
#> $ result_id                                                                       <int> …
#> $ cdm_name                                                                        <chr> …
#> $ group_name                                                                      <chr> …
#> $ strata_name                                                                     <chr> …
#> $ strata_level                                                                    <chr> …
#> $ variable_name                                                                   <chr> …
#> $ variable_level                                                                  <chr> …
#> $ estimate_name                                                                   <chr> …
#> $ estimate_type                                                                   <chr> …
#> $ additional_name                                                                 <chr> …
#> $ additional_level                                                                <chr> …
#> $ `[header]Names of the cohorts\n[header_name]group_level\n[header_level]cohort1` <chr> …
#> $ `[header]Names of the cohorts\n[header_name]group_level\n[header_level]cohort2` <chr> …

The label keys can be removed with includeHeaderKey set to FALSE. However, having these keys in our header will allow to style separately the different header types in the next step (fxTable and gtTable). If we wish to remove the header pointing to the column name (group_level), we can set includeHeaderName to FALSE.

Continuing with our example, we want to pivot by strata (name and level), but, we do not want the column names (that is, strata_name and strata_level) to appear in the header:

mock_sr <- mock_sr |>
  mutate(across(c("strata_name", "strata_level"), ~ gsub("&&&", "and", .x))) |>
  formatHeader(
    header = c("Stratifications", "strata_name", "strata_level"),
    delim = "\n",
    includeHeaderName = FALSE,
    includeHeaderKey = TRUE
  ) 

mock_sr |> glimpse()
#> Rows: 8
#> Columns: 19
#> $ result_id                                                                                 <int> …
#> $ cdm_name                                                                                  <chr> …
#> $ group_name                                                                                <chr> …
#> $ group_level                                                                               <chr> …
#> $ variable_name                                                                             <chr> …
#> $ variable_level                                                                            <chr> …
#> $ estimate_name                                                                             <chr> …
#> $ estimate_type                                                                             <chr> …
#> $ additional_name                                                                           <chr> …
#> $ additional_level                                                                          <chr> …
#> $ `[header]Stratifications\n[header_level]overall\n[header_level]overall`                   <chr> …
#> $ `[header]Stratifications\n[header_level]age_group and sex\n[header_level]<40 and Male`    <chr> …
#> $ `[header]Stratifications\n[header_level]age_group and sex\n[header_level]>=40 and Male`   <chr> …
#> $ `[header]Stratifications\n[header_level]age_group and sex\n[header_level]<40 and Female`  <chr> …
#> $ `[header]Stratifications\n[header_level]age_group and sex\n[header_level]>=40 and Female` <chr> …
#> $ `[header]Stratifications\n[header_level]sex\n[header_level]Male`                          <chr> …
#> $ `[header]Stratifications\n[header_level]sex\n[header_level]Female`                        <chr> …
#> $ `[header]Stratifications\n[header_level]age_group\n[header_level]<40`                     <chr> …
#> $ `[header]Stratifications\n[header_level]age_group\n[header_level]>=40`                    <chr> …

Notice, how we substitute the keyWord “&&&” to “and”, to get a nice header.

4. gtTable() and fxTable()

Finally, we have the functions gtTable and fxTable which will transform our tibble into a gt or flextable object respectively. These functions provide several tools to personalise the formatted table.

gtTable()

Let’s start by manipulating the dataframe to have the columns that we want to display, and then use gtTable with default values:

# first we select the columns we want:
mock_sr <- mock_sr |>
  splitGroup() |>
  select(!all_of(c(
    "cdm_name", "estimate_type", "result_id","additional_name", 
    "additional_level"
  ))) 
mock_sr |>  gtTable()
Stratifications
cohort_name variable_name variable_level estimate_name overall age_group and sex sex age_group
overall <40 and Male >=40 and Male <40 and Female >=40 and Female Male Female <40 >=40
cohort1 number subjects - N 8,826,168 1,767,348 6,631,712 6,027,918 5,296,819 2,990,645 2,107,901 100,803 2,429,801
cohort2 number subjects - N 3,205,919 3,004,673 61,946 1,563,296 8,178,695 4,689,618 5,269,761 7,454,053 6,434,748
cohort1 age - Mean (SD) 72.16 (9.40) 66.69 (9.58) 73.34 (8.17) 35.38 (6.01) 86.30 (3.36) 91.66 (1.72) 87.74 (4.60) 0.04 (5.20) 89.44 (3.83)
cohort2 age - Mean (SD) 24.40 (5.84) 17.97 (2.92) 63.37 (3.44) 13.70 (7.77) 49.16 (3.39) 29.21 (6.83) 33.28 (5.94) 30.77 (9.68) 50.74 (4.00)
cohort1 Medications Amoxiciline N (%) 14,904 (62.3%) 36,859 (52.3%) 32,808 (38.5%) 70,215 (99.3%) 74,512 (94.0%) 17,917 (61.2%) 85,789 (35.2%) 72,014 (59.9%) 97,692 (12.8%)
cohort2 Medications Amoxiciline N (%) 24,313 (61.7%) 18,516 (47.0%) 25,865 (50.3%) 40,591 (22.8%) 58,752 (50.4%) 21,733 (11.2%) 77,194 (97.3%) 4,518 (2.6%) 98,493 (76.5%)
cohort1 Medications Ibuprofen N (%) 85,479 (79.1%) 60,891 (43.4%) 92,090 (58.1%) 77,550 (88.3%) 46,737 (65.8%) 77,591 (32.4%) 35,895 (8.5%) 15,952 (27.5%) 22,520 (32.2%)
cohort2 Medications Ibuprofen N (%) 11,467 (46.1%) 11,733 (13.2%) 86,629 (31.4%) 57,503 (95.9%) 7,652 (18.4%) 83,903 (8.3%) 74,623 (79.8%) 54,106 (20.1%) 84,108 (58.9%)

Now, we want to group results by “cohort_name”. More specifically we want to have a row which the name of each cohort before the results of that cohort, and that cohort1 comes before cohort2. Additionally, we want to merge those rows what contain the same information for all the columns. To get this table we will use gtTable as follows:

mock_sr |>  
  gtTable(
    groupNameCol = "cohort_name",
    groupNameAsColumn = FALSE,
    groupOrder = c("cohort1", "cohort2"),
    colsToMergeRows = "all_columns"
  )
Stratifications
cohort_name variable_name variable_level estimate_name overall age_group and sex sex age_group
overall <40 and Male >=40 and Male <40 and Female >=40 and Female Male Female <40 >=40
cohort1 number subjects - N 8,826,168 1,767,348 6,631,712 6,027,918 5,296,819 2,990,645 2,107,901 100,803 2,429,801
cohort2 number subjects - N 3,205,919 3,004,673 61,946 1,563,296 8,178,695 4,689,618 5,269,761 7,454,053 6,434,748
cohort1 age - Mean (SD) 72.16 (9.40) 66.69 (9.58) 73.34 (8.17) 35.38 (6.01) 86.30 (3.36) 91.66 (1.72) 87.74 (4.60) 0.04 (5.20) 89.44 (3.83)
cohort2 age - Mean (SD) 24.40 (5.84) 17.97 (2.92) 63.37 (3.44) 13.70 (7.77) 49.16 (3.39) 29.21 (6.83) 33.28 (5.94) 30.77 (9.68) 50.74 (4.00)
cohort1 Medications Amoxiciline N (%) 14,904 (62.3%) 36,859 (52.3%) 32,808 (38.5%) 70,215 (99.3%) 74,512 (94.0%) 17,917 (61.2%) 85,789 (35.2%) 72,014 (59.9%) 97,692 (12.8%)
cohort2 Medications Amoxiciline N (%) 24,313 (61.7%) 18,516 (47.0%) 25,865 (50.3%) 40,591 (22.8%) 58,752 (50.4%) 21,733 (11.2%) 77,194 (97.3%) 4,518 (2.6%) 98,493 (76.5%)
cohort1 Medications Ibuprofen N (%) 85,479 (79.1%) 60,891 (43.4%) 92,090 (58.1%) 77,550 (88.3%) 46,737 (65.8%) 77,591 (32.4%) 35,895 (8.5%) 15,952 (27.5%) 22,520 (32.2%)
cohort2 Medications Ibuprofen N (%) 11,467 (46.1%) 11,733 (13.2%) 86,629 (31.4%) 57,503 (95.9%) 7,652 (18.4%) 83,903 (8.3%) 74,623 (79.8%) 54,106 (20.1%) 84,108 (58.9%)

We might also want to modify the default style of the table. For instance, we might want to highlight the cohort_name labels with a blue background, have the body text in red, and use a combination of orange and yellow for the header. We can do it with the style argument:

mock_sr |>  
  gtTable(
    style = list(
      "header" = list(gt::cell_text(weight = "bold"), 
                      gt::cell_fill(color = "orange")),
      "header_level" = list(gt::cell_text(weight = "bold"), 
                      gt::cell_fill(color = "yellow")),
      "column_name" = gt::cell_text(weight = "bold"),
      "group_label" = list(gt::cell_fill(color = "blue"),
                           gt::cell_text(color = "white", weight = "bold")),
      "body" = gt::cell_text(color = "red")
    ),
    groupNameCol = "cohort_name",
    groupNameAsColumn = FALSE,
    groupOrder = c("cohort1", "cohort2"),
    colsToMergeRows = "all_columns"
  )
Stratifications
cohort_name variable_name variable_level estimate_name overall age_group and sex sex age_group
overall <40 and Male >=40 and Male <40 and Female >=40 and Female Male Female <40 >=40
cohort1 number subjects - N 8,826,168 1,767,348 6,631,712 6,027,918 5,296,819 2,990,645 2,107,901 100,803 2,429,801
cohort2 number subjects - N 3,205,919 3,004,673 61,946 1,563,296 8,178,695 4,689,618 5,269,761 7,454,053 6,434,748
cohort1 age - Mean (SD) 72.16 (9.40) 66.69 (9.58) 73.34 (8.17) 35.38 (6.01) 86.30 (3.36) 91.66 (1.72) 87.74 (4.60) 0.04 (5.20) 89.44 (3.83)
cohort2 age - Mean (SD) 24.40 (5.84) 17.97 (2.92) 63.37 (3.44) 13.70 (7.77) 49.16 (3.39) 29.21 (6.83) 33.28 (5.94) 30.77 (9.68) 50.74 (4.00)
cohort1 Medications Amoxiciline N (%) 14,904 (62.3%) 36,859 (52.3%) 32,808 (38.5%) 70,215 (99.3%) 74,512 (94.0%) 17,917 (61.2%) 85,789 (35.2%) 72,014 (59.9%) 97,692 (12.8%)
cohort2 Medications Amoxiciline N (%) 24,313 (61.7%) 18,516 (47.0%) 25,865 (50.3%) 40,591 (22.8%) 58,752 (50.4%) 21,733 (11.2%) 77,194 (97.3%) 4,518 (2.6%) 98,493 (76.5%)
cohort1 Medications Ibuprofen N (%) 85,479 (79.1%) 60,891 (43.4%) 92,090 (58.1%) 77,550 (88.3%) 46,737 (65.8%) 77,591 (32.4%) 35,895 (8.5%) 15,952 (27.5%) 22,520 (32.2%)
cohort2 Medications Ibuprofen N (%) 11,467 (46.1%) 11,733 (13.2%) 86,629 (31.4%) 57,503 (95.9%) 7,652 (18.4%) 83,903 (8.3%) 74,623 (79.8%) 54,106 (20.1%) 84,108 (58.9%)

fxTable()

To obtain a similar result but with a flextable object, we can use fxTable with the same arguments as before, however, style must be adapted to use the officer package since it is the accepted by flextable.

mock_sr |>  
  fxTable(
    style = list(
      "header" = list(
        "cell" = officer::fp_cell(background.color = "orange"),
        "text" = officer::fp_text(bold = TRUE)),
      "header_level" = list(
        "cell" = officer::fp_cell(background.color = "yellow"),
        "text" = officer::fp_text(bold = TRUE)),
      "column_name" = list("text" = officer::fp_text(bold = TRUE)),
      "group_label" = list(
        "cell" = officer::fp_cell(background.color = "blue"),
        "text" = officer::fp_text(bold = TRUE, color = "white")),
      "body" = list("text" = officer::fp_text(color = "red"))
    ),
    groupNameCol = "cohort_name",
    groupNameAsColumn = FALSE,
    groupOrder = c("cohort1", "cohort2"),
    colsToMergeRows = "all_columns"
  )

cohort_name

variable_name

variable_level

estimate_name

Stratifications

overall

age_group and sex

sex

age_group

overall

<40 and Male

>=40 and Male

<40 and Female

>=40 and Female

Male

Female

<40

>=40

cohort1

number subjects

-

N

8,826,168

1,767,348

6,631,712

6,027,918

5,296,819

2,990,645

2,107,901

100,803

2,429,801

cohort2

number subjects

-

N

3,205,919

3,004,673

61,946

1,563,296

8,178,695

4,689,618

5,269,761

7,454,053

6,434,748

cohort1

age

-

Mean (SD)

72.16 (9.40)

66.69 (9.58)

73.34 (8.17)

35.38 (6.01)

86.30 (3.36)

91.66 (1.72)

87.74 (4.60)

0.04 (5.20)

89.44 (3.83)

cohort2

age

-

Mean (SD)

24.40 (5.84)

17.97 (2.92)

63.37 (3.44)

13.70 (7.77)

49.16 (3.39)

29.21 (6.83)

33.28 (5.94)

30.77 (9.68)

50.74 (4.00)

cohort1

Medications

Amoxiciline

N (%)

14,904 (62.3%)

36,859 (52.3%)

32,808 (38.5%)

70,215 (99.3%)

74,512 (94.0%)

17,917 (61.2%)

85,789 (35.2%)

72,014 (59.9%)

97,692 (12.8%)

cohort2

Medications

Amoxiciline

N (%)

24,313 (61.7%)

18,516 (47.0%)

25,865 (50.3%)

40,591 (22.8%)

58,752 (50.4%)

21,733 (11.2%)

77,194 (97.3%)

4,518 (2.6%)

98,493 (76.5%)

cohort1

Medications

Ibuprofen

N (%)

85,479 (79.1%)

60,891 (43.4%)

92,090 (58.1%)

77,550 (88.3%)

46,737 (65.8%)

77,591 (32.4%)

35,895 (8.5%)

15,952 (27.5%)

22,520 (32.2%)

cohort2

Medications

Ibuprofen

N (%)

11,467 (46.1%)

11,733 (13.2%)

86,629 (31.4%)

57,503 (95.9%)

7,652 (18.4%)

83,903 (8.3%)

74,623 (79.8%)

54,106 (20.1%)

84,108 (58.9%)

visOmopTable(): all at once

This function wraps the tools seen so far to format a summarised result at once. While it is convenient to have it all in one function, the level of table manipulation allowed is less than with the pipeline.

First, we create a new mock summarised result:

mock_sr2 <- mockSummarisedResult()

For instance, if we want to have a flextable with strata as header, we will write “strata” in header instead of strata_name and strata_level. Same as before, we can input header keys (e.g. “Stratifications” in the example below).

The split argument points to which name-level columns to split (group, strata and/or additional). Refer to the vignette split and unite for further information on this functionality.

mock_sr2 |> visOmopTable(
  formatEstimateName = c("N%" = "<count> (<percentage>)",
                         "N" = "<count>",
                         "Mean (SD)" = "<mean> (<sd>)"),
  header = c("Stratifications", "strata"),
  split = c("group","additional")
)
Stratifications
CDM name Cohort name Variable name Variable level Estimate name Overall Age group and sex Sex Age group
Overall <40 and male >=40 and male <40 and female >=40 and female Male Female <40 >=40
mock Cohort1 Number subjects - N 1,134,267 5,557,051 5,102,396 3,989,397 3,079,447 1,820,296 724,458 921,677 8,922,077
Cohort2 Number subjects - N 8,918,568 1,281,024 674,074 6,275,373 3,252,495 7,854,263 9,679,453 3,341,150 9,986,758
Cohort1 Age - Mean (SD) 58.01 (6.10) 66.55 (1.68) 32.47 (0.29) 62.54 (4.31) 91.59 (6.85) 3.58 (4.62) 37.39 (4.26) 6.96 (5.61) 26.55 (8.08)
Cohort2 Age - Mean (SD) 15.98 (0.16) 77.07 (6.22) 20.40 (6.72) 94.29 (0.64) 36.42 (7.28) 12.93 (7.59) 80.00 (6.13) 4.94 (0.62) 22.12 (2.14)
Cohort1 Medications Amoxiciline N% 71,044 (29.14) 74,329 (14.41) 80,310 (9.77) 84,746 (72.63) 37,356 (72.46) 70,583 (96.98) 37,600 (59.50) 55,404 (90.49) 91,880 (56.48)
Cohort2 Medications Amoxiciline N% 92,719 (55.14) 71,396 (49.80) 49,112 (50.15) 90,020 (21.43) 47,464 (59.40) 45,271 (86.78) 74,661 (54.73) 81,400 (5.12) 80,329 (39.45)
Cohort1 Medications Ibuprofen N% 3,077 (91.01) 38,646 (75.34) 97,863 (53.67) 4,225 (45.43) 86,816 (60.42) 69,742 (98.75) 56,711 (70.30) 53,416 (55.29) 31,601 (72.43)
Cohort2 Medications Ibuprofen N% 87,647 (39.95) 31,739 (2.71) 26,324 (49.97) 3,330 (15.82) 67,220 (37.91) 4,040 (52.92) 7,467 (1.37) 11,517 (19.49) 6,431 (14.15)

By default, it returns a gt table, but it can be changed to “flextable” and “tibble” in the type argument.

The groupColumn can be used to create groups in the table body. For instance, looking at the previous table, we might want to group by cohort name:

mock_sr2 |> visOmopTable(
  formatEstimateName = c("N%" = "<count> (<percentage>)",
                         "N" = "<count>",
                         "Mean (SD)" = "<mean> (<sd>)"),
  header = c("Stratifications", "strata"),
  split = c("group","additional"),
  groupColumn = "cohort_name"
)
Stratifications
CDM name Variable name Variable level Estimate name Overall Age group and sex Sex Age group
Overall <40 and male >=40 and male <40 and female >=40 and female Male Female <40 >=40
Cohort1
mock Number subjects - N 1,134,267 5,557,051 5,102,396 3,989,397 3,079,447 1,820,296 724,458 921,677 8,922,077
Age - Mean (SD) 58.01 (6.10) 66.55 (1.68) 32.47 (0.29) 62.54 (4.31) 91.59 (6.85) 3.58 (4.62) 37.39 (4.26) 6.96 (5.61) 26.55 (8.08)
Medications Amoxiciline N% 71,044 (29.14) 74,329 (14.41) 80,310 (9.77) 84,746 (72.63) 37,356 (72.46) 70,583 (96.98) 37,600 (59.50) 55,404 (90.49) 91,880 (56.48)
Ibuprofen N% 3,077 (91.01) 38,646 (75.34) 97,863 (53.67) 4,225 (45.43) 86,816 (60.42) 69,742 (98.75) 56,711 (70.30) 53,416 (55.29) 31,601 (72.43)
Cohort2
mock Number subjects - N 8,918,568 1,281,024 674,074 6,275,373 3,252,495 7,854,263 9,679,453 3,341,150 9,986,758
Age - Mean (SD) 15.98 (0.16) 77.07 (6.22) 20.40 (6.72) 94.29 (0.64) 36.42 (7.28) 12.93 (7.59) 80.00 (6.13) 4.94 (0.62) 22.12 (2.14)
Medications Amoxiciline N% 92,719 (55.14) 71,396 (49.80) 49,112 (50.15) 90,020 (21.43) 47,464 (59.40) 45,271 (86.78) 74,661 (54.73) 81,400 (5.12) 80,329 (39.45)
Ibuprofen N% 87,647 (39.95) 31,739 (2.71) 26,324 (49.97) 3,330 (15.82) 67,220 (37.91) 4,040 (52.92) 7,467 (1.37) 11,517 (19.49) 6,431 (14.15)

Additional options can be specified in the .options argument. These options are taken from the other format functions and gt/fx table functions seen before. To see a list of allowed arguments and their default values use optionsVisOmopTable():

optionsVisOmopTable()
#> $decimals
#>    integer percentage    numeric proportion 
#>          0          2          2          2 
#> 
#> $decimalMark
#> [1] "."
#> 
#> $bigMark
#> [1] ","
#> 
#> $keepNotFormatted
#> [1] TRUE
#> 
#> $useFormatOrder
#> [1] TRUE
#> 
#> $delim
#> [1] "\n"
#> 
#> $includeHeaderKey
#> [1] TRUE
#> 
#> $style
#> [1] "default"
#> 
#> $na
#> [1] "-"
#> 
#> $title
#> NULL
#> 
#> $subtitle
#> NULL
#> 
#> $caption
#> NULL
#> 
#> $groupAsColumn
#> [1] FALSE
#> 
#> $groupOrder
#> NULL
#> 
#> $colsToMergeRows
#> [1] "all_columns"