Skip to content

Commit 6161e7a

Browse files
flextable
1 parent c55c401 commit 6161e7a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Imports:
2929
yaml
3030
Suggests:
3131
curl,
32+
flextable,
3233
ggplot2,
3334
knitr,
3435
rsconnect (>= 0.8.26),

R/theme.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,36 @@ ggplot_theme_brand <- function(brand_yml) {
3838
brand <- yaml::yaml.load_file(brand_yml)
3939
ggplot_theme_colors(brand$color$background, brand$color$foreground)
4040
}
41+
42+
43+
#' Create a flextable theme using background and foreground colors
44+
#'
45+
#' Create a flextable theme that uses the specified background and
46+
#' foreground colors.
47+
#'
48+
#' @param bg The background color
49+
#' @param fg The foreground color
50+
#'
51+
#' @export
52+
flextable_theme_colors <- function(bg, fg) {
53+
(function(x) {
54+
if (!inherits(x, "flextable")) {
55+
stop("flextable_theme_colors only supports flextable objects.")
56+
}
57+
x <- flextable::bg(x, bg = bg, part = "all")
58+
x <- flextable::color(x, color = fg, part = "all")
59+
flextable::autofit(x)
60+
})
61+
}
62+
63+
#' Create a flextable theme from a brand.yml file
64+
#'
65+
#' Create a flextable theme that uses colors from the brand file.
66+
#'
67+
#' @param brand_yml The path to the brand.yml file
68+
#'
69+
#' @export
70+
flextable_theme_brand <- function(brand_yml) {
71+
brand <- yaml::yaml.load_file(brand_yml)
72+
flextable_theme_colors(brand$color$background, brand$color$foreground)
73+
}

0 commit comments

Comments
 (0)