# NOT RUN {
library(flextable)
f1 <- function(x) {
formatC(x, digits = 1,
format = "f")
}
f2 <- function(x) {
paste0(
" (",
formatC(x, digits = 1,
format = "f"), ")")
}
ft_1 <- flextable(
data = head(mtcars),
col_keys = c("am", "gear", "carb", "mycol")
)
ft_1 <- merge_v(ft_1, j = "am")
ft_1 <- valign(ft_1, valign = "top")
ft_1 <- theme_vanilla(ft_1)
ft_1 <- mk_par(ft_1,
j = "mycol", part = "body",
value = as_paragraph(
as_chunk(mpg, formatter = f1), " ",
colorize(as_chunk(wt, formatter = f2), "gray")
)
)
ft_1 <-
append_chunks(ft_1,
i = 1, j = "mycol", part = "header",
as_chunk("mpg "),
colorize(as_bracket("wt"), "gray")
)
ft_1 <- align(
x = ft_1, j = c("am", "gear", "carb"),
align = "center", part = "all")
ft_1 <- align(
x = ft_1, j = "mycol",
align = "right", part = "all")
ft_1 <- autofit(ft_1)
ft_1
# }
Run the code above in your browser using DataLab