Skip to contents

Creates a flextable object from a dataframe using a delimiter to span the header, and allows to easily customise table style.

Usage

fxTable(
  x,
  delim = "\n",
  style = "default",
  na = "-",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  groupColumn = NULL,
  groupNameCol = lifecycle::deprecated(),
  groupAsColumn = FALSE,
  groupNameAsColumn = lifecycle::deprecated(),
  groupOrder = NULL,
  colsToMergeRows = NULL
)

Arguments

x

A dataframe.

delim

Delimiter.

style

Named list that specifies how to style the different parts of the gt table. Accepted entries are: title, subtitle, header, header_name, header_level, column_name, group_label, and body. Alternatively, use "default" to get visOmopResults style, or NULL for flextable style.

na

How to display missing values.

title

Title of the table, or NULL for no title.

subtitle

Subtitle of the table, or NULL for no subtitle.

caption

Caption for the table, or NULL for no caption. Text in markdown formatting style (e.g. *Your caption here* for caption in italics).

groupColumn

Specifies the columns to use for group labels. By default, the new group name will be a combination of the column names, joined by "_". To assign a custom group name, provide a named list such as: list(newGroupName = c("variable_name", "variable_level"))

groupNameCol

[Deprecated]

groupAsColumn

Whether to display the group labels as a column (TRUE) or rows (FALSE).

groupNameAsColumn

[Deprecated]

groupOrder

Order in which to display group labels.

colsToMergeRows

Names of the columns to merge vertically when consecutive row cells have identical values. Alternatively, use "all_columns" to apply this merging to all columns, or use NULL to indicate no merging.

Value

A flextable object.

A flextable object.

Examples

mockSummarisedResult() |>
  formatEstimateValue(decimals = c(integer = 0, numeric = 1)) |>
  formatHeader(
    header = c("Study strata", "strata_name", "strata_level"),
    includeHeaderName = FALSE
  ) |>
  fxTable(
    style = "default",
    na = "--",
    title = "fxTable example",
    subtitle = NULL,
    caption = NULL,
    groupColumn = "group_level",
    groupAsColumn = TRUE,
    groupOrder = c("cohort1", "cohort2"),
    colsToMergeRows = "all_columns"
  )

fxTable example

group_level

result_id

cdm_name

group_name

variable_name

variable_level

estimate_name

estimate_type

additional_name

additional_level

Study strata

overall

age_group &&& sex

sex

age_group

overall

<40 &&& Male

>=40 &&& Male

<40 &&& Female

>=40 &&& Female

Male

Female

<40

>=40

cohort1

1

mock

cohort_name

number subjects

--

count

integer

overall

overall

5,138,669

1,432,664

6,502,987

1,552,945

5,083,099

858,704

5,030,267

385,719

8,240,329

age

--

mean

numeric

overall

overall

96.7

8.6

24.0

63.9

50.3

25.1

97.9

65.7

9.0

sd

numeric

overall

overall

2.0

7.3

1.7

2.3

8.5

3.5

0.7

0.3

1.2

Medications

Amoxiciline

count

integer

overall

overall

49,583

24,379

25,575

55,232

25,158

62,845

31,612

92,452

90,649

percentage

percentage

overall

overall

58.8247172767296

88.0309032043442

71.9317963346839

93.6428893357515

42.943161376752

28.618732560426

77.0643183263019

61.6498636547476

15.9274747595191

Ibuprofen

count

integer

overall

overall

53,041

42,983

80,930

92,256

67,502

9,397

19,746

47,555

71,437

percentage

percentage

overall

overall

31.5731404349208

81.6187682561576

54.5915438327938

94.7317183716223

3.8526406744495

64.764387672767

7.96190109103918

43.2930769631639

76.0893133934587

cohort2

1

mock

cohort_name

number subjects

--

count

integer

overall

overall

2,859,856

2,467,509

3,979,936

6,320,929

9,485,788

3,401,192

6,273,660

8,249,154

1,451,154

age

--

mean

numeric

overall

overall

63.1

87.7

93.0

41.9

49.6

35.3

24.9

95.9

36.0

sd

numeric

overall

overall

0.1

7.4

9.2

9.8

4.1

2.7

4.9

0.5

0.0

Medications

Amoxiciline

count

integer

overall

overall

9,197

73,780

56,974

69,649

70,077

3,994

43,152

81,423

56,659

percentage

percentage

overall

overall

40.1598005788401

0.164648867212236

41.7966035660356

76.3934360351413

79.4477666728199

24.2587020387873

75.9170953882858

2.91041533928365

43.7340782955289

Ibuprofen

count

integer

overall

overall

53,808

87,538

29,359

22,477

69,092

31,233

48,330

12,180

69,001

percentage

percentage

overall

overall

29.3758839834481

10.7331892941147

7.29944417253137

35.6314577395096

57.1560842683539

67.7988059120253

69.0719101810828

37.3410821193829

9.79780545458198