CreateFLX: Create a flextable object from data provided

Description Usage Arguments Value Examples

Description

Create a flextable object generated from data and settings provided

Usage

1
CreateFLX(df_struct)

Arguments

df_struct

a list including the data structure and all properties to represent these data with in a table. This data structure includes the next obligatory elements:

data

a dataframe prepared for conversion into the flextable object. It's up to user to format the dataframe with raw data into this format, because each statistical table has it's own unique format.

The next elements of the df_struct are optional, thus can omitted, and should be used for making the unique design of the generated flextable object. Each flextable object consists of header, body and footer parts the detailed description of which can be found in the documentation of flextable package.

header

a named list of ordered arrays representing the names of the columns. Each element in the list corresponds to the new row in a flextable header part. Any flextable object always consists of a header part. If no header element is provided, then the names of the original dataframe are used for constructing the flextable object header

footer

a named list of ordered arrays representing the footer part of the flextable object. Each element in the list corresponds to the new row in a flextable footer part. A flextable object may include no footer part

rows_to_merge

indexes of rows to merge vertically in a body part

columns_to_merge

indexes of columns to merge horizontally in a body part

cells_to_merge

a list of elements represanting the rectangular area of the dataframe body to merge. Each element is a list consisting of two subelements: rows and columns, each of which is a range of rows or columns respectively defining the rectangular. All cells in either footer or header parts with the same value are merged automatically

table_width

an array of column widths. If omitted, columns widths are uniformly distributed provided that the table total width equals to 6.54 inches corresponding to a Word vertical oriented table

font

font size of all data in a table. If omitted, 10 points is used

rows_as_footnote_title

indexes of rows corresponding to the local titles which should be highlighted with italic font (Note, Designation, etc.) in a footer part. The value of this element doesn't effect on the generated flextable in case no footer is provided. If omitted, the first row is highlighted

columns_left_align

indexes of columns to left align in a body part

rows_as_inner_headers

indexes of rows corresponding to the names of measured clinical quantities in a body part and should be colored

rows_section_init

indexes of rows corresponding to the names of statistical methods and sections in a body part and should be highlighted

rows_bold_upper_bordered

indexes of rows with an upper border to highlight in a body part

cells_color

a list of cells to color where a cell is a list with two elements: row and column

rows_p_value_color

indexes of rows with p-value data to check for colouring

Value

The flextable object. Can be overviewed in the inbuilt Rstudio Viewer.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# a table with a complex header and footer
t_data <- head(mtcars)
t_df_struct <- list(data = t_data,
                    header = list(row1 = rep("all columns", ncol(t_data)),
                                  row2 = c(rep("1st column groups", floor(ncol(t_data)/2)),
                                           rep("2st column groups", ceiling(ncol(t_data)/2))),
                                  row3 = names(t_data)),
                    footer = list(row1 = rep("Note:", ncol(t_data)),
                                  row2 = rep("Nothing special for this table", ncol(t_data))))
CreateFLX(t_df_struct)

# a table with all possible design modifications
t_data <- dplyr::mutate_all(mtcars[1:3, 1:5], as.character) %>%
         dplyr::add_row(mpg = "population A", cyl = "population A", disp = "population A",
                        hp = "population A", drat = "population A")  %>%
         dplyr::bind_rows(dplyr::mutate_all(mtcars[4:6, 1:5], as.character)) %>%
         dplyr::add_row(mpg = "norm test:", cyl = "norm test:", disp = "norm test:",
                        hp = "norm test:", drat = "norm test:") %>%
         dplyr::add_row(mpg = "p = 0.43", cyl = "p < 0,001", disp = "p = 0,44",
                        hp = "p = 0.004", drat = "p = 0.002") %>%
         dplyr::bind_rows(dplyr::mutate_all(mtcars[7:9, 1:5], as.character)) %>%
         dplyr::add_row(mpg = "population B", cyl = "population B", disp = "population B",
                        hp = "population B", drat = "population B") %>%
         dplyr::bind_rows(dplyr::mutate_all(mtcars[10:12, 1:5], as.character))
t_df_struct <- list(data = t_data,
                   header = list(row1 = rep("all columns", ncol(t_data)),
                                 row2 = c(rep("1st column group", floor(ncol(t_data)/2)),
                                          rep("2st column group", ceiling(ncol(t_data)/2))),
                                 row3 = names(t_data)),
                   footer = list(row1 = rep("Note:", ncol(t_data)),
                                 row2 = rep("Nothing special for this table", ncol(t_data)),
                                 row3 = rep("Designation:", ncol(t_data)),
                                 row4 = rep("NA - not available", ncol(t_data))),
                   rows_to_merge = c(4, 8, 13),
                   cells_to_merge = list(rect1 = list(rows = 1:2, columns = 1),
                                         rect2 = list(rows = 14:15, columns = 4:5)),
                   columns_to_merge = 5,
                   table_width = NULL,
                   font = 12,
                   rows_as_footnote_title = c(1, 3),
                   rows_as_inner_headers = c(4, 13),
                   rows_section_init = 8,
                   columns_left_align = c(2, 4),
                   rows_bold_upper_bordered = 15,
                   cells_color = list(cell1 = list(row = 15, column = 1),
                                      cell2 = list(row = 16, column = 2)),
                   rows_p_value_color = 9)
CreateFLX(t_df_struct)

Gargantua404/SmoothExport documentation built on July 1, 2019, 1:27 a.m.