analysisfun <- function(x, ...) {
in_rows(
row1 = 5,
row2 = c(1, 2),
.row_footnotes = list(row1 = "row 1 - row footnote"),
.cell_footnotes = list(row2 = "row 2 - cell footnote")
)
}
lyt <- basic_table(
title = "Title says Whaaaat", subtitles = "Oh, ok.",
main_footer = "ha HA! Footer!"
) %>%
split_cols_by("ARM") %>%
analyze("AGE", afun = analysisfun)
tbl <- build_table(lyt, ex_adsl)
# Example 1: rtables style ---------------------------------------------------
tt_to_flextable(tbl, theme = NULL)
# Example 2: docx style ------------------------------------------------------
tt_to_flextable(tbl, theme = theme_docx_default(font_size = 6))
# Example 3: Extending the docx theme ----------------------------------------
my_theme <- function(x, ...) {
flextable::border_inner(x, part = "body", border = flextable::fp_border_default(width = 0.5))
}
flx <- tt_to_flextable(tbl, theme = c(theme_docx_default(), my_theme))
# Example 4: Creating a custom theme -----------------------------------------
special_bold <- list(
"header" = list("i" = 1, "j" = c(1, 3)),
"body" = list("i" = c(1, 2), "j" = 1)
)
custom_theme <- theme_docx_default(
font_size = 10,
font = "Brush Script MT",
border = flextable::fp_border_default(color = "pink", width = 2),
bold = NULL,
bold_manual = special_bold
)
tt_to_flextable(tbl,
border = flextable::fp_border_default(color = "pink", width = 2),
theme = custom_theme
)
# Example 5: Extending the docx theme ----------------------------------------
my_theme <- function(font_size = 6) { # here can pass additional arguments for default theme
function(flx, ...) {
# First apply theme_docx_default
flx <- theme_docx_default(font_size = font_size)(flx, ...)
# Then apply additional styling
flx <- flextable::border_inner(flx,
part = "body",
border = flextable::fp_border_default(width = 0.5)
)
return(flx)
}
}
flx <- tt_to_flextable(tbl, theme = my_theme())
# html theme
# Define a layout for the table
lyt <- basic_table() %>%
# Split columns by the "ARM" variable
split_cols_by("ARM") %>%
# Analyze the "AGE", "BMRKR2", and "COUNTRY" variables
analyze(c("AGE", "BMRKR2", "COUNTRY"))
# Build the table using the defined layout and example data 'ex_adsl'
tbl <- build_table(lyt, ex_adsl)
# Convert the table to a flextable object suitable for HTML,
# applying the default HTML theme and setting the orientation to landscape
tbl_html <- tt_to_flextable(
tbl,
theme = theme_html_default(),
section_properties = section_properties_default(orientation = "landscape")
)
# Save the flextable as an HTML file named "test.html"
flextable::save_as_html(tbl_html,
path = tempfile(tmpdir = tempdir(check = TRUE), fileext = ".html")
)
Run the code above in your browser using DataLab