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> "807501", "8343330", "6007609", "1572084", "73994", "…
#> $ 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> "807,501", "8,343,330", "6,007,609", "1,572,084", "73…
#> $ 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> "807,501", "8,343,330", "6,007,609", "1,572,084", "73…
#> $ 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”.
-
header: Header labels passed to
header
but which are not part of the input table (are not columns names or values). - header_name: Header labels that come from column names in the input table.
- header_level: Header labels that come from values of selected columns in the input table.
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 | 807,501 | 8,343,330 | 6,007,609 | 1,572,084 | 73,994 | 4,663,935 | 4,977,774 | 2,897,672 | 7,328,820 |
cohort2 | number subjects | - | N | 7,725,215 | 8,746,007 | 1,749,406 | 342,413 | 3,203,857 | 4,023,282 | 1,956,698 | 4,035,381 | 636,615 |
cohort1 | age | - | Mean (SD) | 38.87 (7.06) | 97.55 (9.49) | 28.99 (1.80) | 67.84 (2.17) | 73.53 (6.80) | 19.60 (4.99) | 98.05 (6.42) | 74.15 (6.60) | 5.14 (0.96) |
cohort2 | age | - | Mean (SD) | 53.02 (7.66) | 69.58 (7.70) | 68.86 (9.91) | 3.12 (9.71) | 22.56 (3.89) | 30.08 (4.61) | 63.65 (3.15) | 47.90 (1.75) | 43.22 (5.32) |
cohort1 | Medications | Amoxiciline | N (%) | 49,364 (2.8%) | 77,931 (46.6%) | 20,418 (39.0%) | 71,340 (2.0%) | 6,522 (37.7%) | 35,421 (56.0%) | 82,520 (85.7%) | 27,382 (38.5%) | 57,004 (52.8%) |
cohort2 | Medications | Amoxiciline | N (%) | 33,572 (60.1%) | 59,626 (26.1%) | 19,152 (29.0%) | 94,776 (48.0%) | 54,248 (92.0%) | 54,460 (40.1%) | 27,860 (21.3%) | 44,670 (67.2%) | 37,151 (5.9%) |
cohort1 | Medications | Ibuprofen | N (%) | 99,707 (51.2%) | 14,904 (83.6%) | 51,856 (70.9%) | 84,612 (87.4%) | 71,827 (1.1%) | 24,131 (88.8%) | 54,704 (99.6%) | 83,480 (50.0%) | 2,796 (35.9%) |
cohort2 | Medications | Ibuprofen | N (%) | 46,938 (77.5%) | 80,568 (58.4%) | 81,405 (63.4%) | 40,391 (85.9%) | 21,843 (56.7%) | 41,836 (25.3%) | 66,887 (91.9%) | 50,765 (86.7%) | 66,036 (24.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 | 807,501 | 8,343,330 | 6,007,609 | 1,572,084 | 73,994 | 4,663,935 | 4,977,774 | 2,897,672 | 7,328,820 |
cohort2 | number subjects | - | N | 7,725,215 | 8,746,007 | 1,749,406 | 342,413 | 3,203,857 | 4,023,282 | 1,956,698 | 4,035,381 | 636,615 |
cohort1 | age | - | Mean (SD) | 38.87 (7.06) | 97.55 (9.49) | 28.99 (1.80) | 67.84 (2.17) | 73.53 (6.80) | 19.60 (4.99) | 98.05 (6.42) | 74.15 (6.60) | 5.14 (0.96) |
cohort2 | age | - | Mean (SD) | 53.02 (7.66) | 69.58 (7.70) | 68.86 (9.91) | 3.12 (9.71) | 22.56 (3.89) | 30.08 (4.61) | 63.65 (3.15) | 47.90 (1.75) | 43.22 (5.32) |
cohort1 | Medications | Amoxiciline | N (%) | 49,364 (2.8%) | 77,931 (46.6%) | 20,418 (39.0%) | 71,340 (2.0%) | 6,522 (37.7%) | 35,421 (56.0%) | 82,520 (85.7%) | 27,382 (38.5%) | 57,004 (52.8%) |
cohort2 | Medications | Amoxiciline | N (%) | 33,572 (60.1%) | 59,626 (26.1%) | 19,152 (29.0%) | 94,776 (48.0%) | 54,248 (92.0%) | 54,460 (40.1%) | 27,860 (21.3%) | 44,670 (67.2%) | 37,151 (5.9%) |
cohort1 | Medications | Ibuprofen | N (%) | 99,707 (51.2%) | 14,904 (83.6%) | 51,856 (70.9%) | 84,612 (87.4%) | 71,827 (1.1%) | 24,131 (88.8%) | 54,704 (99.6%) | 83,480 (50.0%) | 2,796 (35.9%) |
cohort2 | Medications | Ibuprofen | N (%) | 46,938 (77.5%) | 80,568 (58.4%) | 81,405 (63.4%) | 40,391 (85.9%) | 21,843 (56.7%) | 41,836 (25.3%) | 66,887 (91.9%) | 50,765 (86.7%) | 66,036 (24.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 | 807,501 | 8,343,330 | 6,007,609 | 1,572,084 | 73,994 | 4,663,935 | 4,977,774 | 2,897,672 | 7,328,820 |
cohort2 | number subjects | - | N | 7,725,215 | 8,746,007 | 1,749,406 | 342,413 | 3,203,857 | 4,023,282 | 1,956,698 | 4,035,381 | 636,615 |
cohort1 | age | - | Mean (SD) | 38.87 (7.06) | 97.55 (9.49) | 28.99 (1.80) | 67.84 (2.17) | 73.53 (6.80) | 19.60 (4.99) | 98.05 (6.42) | 74.15 (6.60) | 5.14 (0.96) |
cohort2 | age | - | Mean (SD) | 53.02 (7.66) | 69.58 (7.70) | 68.86 (9.91) | 3.12 (9.71) | 22.56 (3.89) | 30.08 (4.61) | 63.65 (3.15) | 47.90 (1.75) | 43.22 (5.32) |
cohort1 | Medications | Amoxiciline | N (%) | 49,364 (2.8%) | 77,931 (46.6%) | 20,418 (39.0%) | 71,340 (2.0%) | 6,522 (37.7%) | 35,421 (56.0%) | 82,520 (85.7%) | 27,382 (38.5%) | 57,004 (52.8%) |
cohort2 | Medications | Amoxiciline | N (%) | 33,572 (60.1%) | 59,626 (26.1%) | 19,152 (29.0%) | 94,776 (48.0%) | 54,248 (92.0%) | 54,460 (40.1%) | 27,860 (21.3%) | 44,670 (67.2%) | 37,151 (5.9%) |
cohort1 | Medications | Ibuprofen | N (%) | 99,707 (51.2%) | 14,904 (83.6%) | 51,856 (70.9%) | 84,612 (87.4%) | 71,827 (1.1%) | 24,131 (88.8%) | 54,704 (99.6%) | 83,480 (50.0%) | 2,796 (35.9%) |
cohort2 | Medications | Ibuprofen | N (%) | 46,938 (77.5%) | 80,568 (58.4%) | 81,405 (63.4%) | 40,391 (85.9%) | 21,843 (56.7%) | 41,836 (25.3%) | 66,887 (91.9%) | 50,765 (86.7%) | 66,036 (24.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 |
807,501 |
8,343,330 |
6,007,609 |
1,572,084 |
73,994 |
4,663,935 |
4,977,774 |
2,897,672 |
7,328,820 |
cohort2 |
number subjects |
- |
N |
7,725,215 |
8,746,007 |
1,749,406 |
342,413 |
3,203,857 |
4,023,282 |
1,956,698 |
4,035,381 |
636,615 |
cohort1 |
age |
- |
Mean (SD) |
38.87 (7.06) |
97.55 (9.49) |
28.99 (1.80) |
67.84 (2.17) |
73.53 (6.80) |
19.60 (4.99) |
98.05 (6.42) |
74.15 (6.60) |
5.14 (0.96) |
cohort2 |
age |
- |
Mean (SD) |
53.02 (7.66) |
69.58 (7.70) |
68.86 (9.91) |
3.12 (9.71) |
22.56 (3.89) |
30.08 (4.61) |
63.65 (3.15) |
47.90 (1.75) |
43.22 (5.32) |
cohort1 |
Medications |
Amoxiciline |
N (%) |
49,364 (2.8%) |
77,931 (46.6%) |
20,418 (39.0%) |
71,340 (2.0%) |
6,522 (37.7%) |
35,421 (56.0%) |
82,520 (85.7%) |
27,382 (38.5%) |
57,004 (52.8%) |
cohort2 |
Medications |
Amoxiciline |
N (%) |
33,572 (60.1%) |
59,626 (26.1%) |
19,152 (29.0%) |
94,776 (48.0%) |
54,248 (92.0%) |
54,460 (40.1%) |
27,860 (21.3%) |
44,670 (67.2%) |
37,151 (5.9%) |
cohort1 |
Medications |
Ibuprofen |
N (%) |
99,707 (51.2%) |
14,904 (83.6%) |
51,856 (70.9%) |
84,612 (87.4%) |
71,827 (1.1%) |
24,131 (88.8%) |
54,704 (99.6%) |
83,480 (50.0%) |
2,796 (35.9%) |
cohort2 |
Medications |
Ibuprofen |
N (%) |
46,938 (77.5%) |
80,568 (58.4%) |
81,405 (63.4%) |
40,391 (85.9%) |
21,843 (56.7%) |
41,836 (25.3%) |
66,887 (91.9%) |
50,765 (86.7%) |
66,036 (24.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 | 9,728,442 | 8,190,824 | 9,029,238 | 5,813,660 | 7,730,085 | 9,951,230 | 7,109,712 | 2,149,426 | 2,917,576 |
Cohort2 | Number subjects | - | N | 7,217,597 | 8,666,157 | 2,384,531 | 44,963 | 9,435,165 | 4,381,372 | 7,506,033 | 6,678,158 | 4,079,732 | |
Cohort1 | Age | - | Mean (SD) | 35.12 (9.06) | 73.81 (7.73) | 66.43 (3.83) | 8.52 (10.00) | 85.61 (3.49) | 7.70 (9.47) | 85.28 (2.16) | 10.63 (0.32) | 48.48 (1.45) | |
Cohort2 | Age | - | Mean (SD) | 24.72 (8.54) | 68.66 (2.13) | 16.36 (2.10) | 95.28 (0.40) | 32.19 (9.45) | 36.15 (2.45) | 88.77 (7.81) | 82.80 (2.88) | 10.07 (8.75) | |
Cohort1 | Medications | Amoxiciline | N% | 29,575 (66.45) | 98,353 (38.96) | 58,984 (4.61) | 75,916 (61.69) | 83,608 (59.85) | 76,282 (40.69) | 41,727 (85.83) | 13,807 (51.77) | 8,084 (97.93) | |
Cohort2 | Medications | Amoxiciline | N% | 65,598 (1.70) | 60,200 (67.34) | 65,700 (37.13) | 32,932 (91.80) | 97,947 (67.80) | 71,519 (66.52) | 87,263 (75.60) | 98,328 (54.28) | 21,856 (23.93) | |
Cohort1 | Medications | Ibuprofen | N% | 50,889 (17.24) | 41,726 (69.07) | 72,695 (67.52) | 63,769 (94.63) | 39,641 (19.62) | 95,948 (96.86) | 29,866 (38.71) | 5,020 (65.03) | 57,619 (81.46) | |
Cohort2 | Medications | Ibuprofen | N% | 21,791 (7.10) | 12,586 (52.68) | 93,815 (76.35) | 80,128 (43.54) | 75,805 (55.25) | 53,257 (20.40) | 54,680 (3.10) | 9,593 (96.97) | 38,835 (17.86) |
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 | 9,728,442 | 8,190,824 | 9,029,238 | 5,813,660 | 7,730,085 | 9,951,230 | 7,109,712 | 2,149,426 | 2,917,576 |
Age | - | Mean (SD) | 35.12 (9.06) | 73.81 (7.73) | 66.43 (3.83) | 8.52 (10.00) | 85.61 (3.49) | 7.70 (9.47) | 85.28 (2.16) | 10.63 (0.32) | 48.48 (1.45) | |
Medications | Amoxiciline | N% | 29,575 (66.45) | 98,353 (38.96) | 58,984 (4.61) | 75,916 (61.69) | 83,608 (59.85) | 76,282 (40.69) | 41,727 (85.83) | 13,807 (51.77) | 8,084 (97.93) | |
Ibuprofen | N% | 50,889 (17.24) | 41,726 (69.07) | 72,695 (67.52) | 63,769 (94.63) | 39,641 (19.62) | 95,948 (96.86) | 29,866 (38.71) | 5,020 (65.03) | 57,619 (81.46) | ||
Cohort2 | ||||||||||||
mock | Number subjects | - | N | 7,217,597 | 8,666,157 | 2,384,531 | 44,963 | 9,435,165 | 4,381,372 | 7,506,033 | 6,678,158 | 4,079,732 |
Age | - | Mean (SD) | 24.72 (8.54) | 68.66 (2.13) | 16.36 (2.10) | 95.28 (0.40) | 32.19 (9.45) | 36.15 (2.45) | 88.77 (7.81) | 82.80 (2.88) | 10.07 (8.75) | |
Medications | Amoxiciline | N% | 65,598 (1.70) | 60,200 (67.34) | 65,700 (37.13) | 32,932 (91.80) | 97,947 (67.80) | 71,519 (66.52) | 87,263 (75.60) | 98,328 (54.28) | 21,856 (23.93) | |
Ibuprofen | N% | 21,791 (7.10) | 12,586 (52.68) | 93,815 (76.35) | 80,128 (43.54) | 75,805 (55.25) | 53,257 (20.40) | 54,680 (3.10) | 9,593 (96.97) | 38,835 (17.86) |
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"