Is there a smart way to have a horizontal border table wide when you have merged cells? (In the example below, it is not yet table wide).
Or should I write a function to calculate the correct index?
library(flextable)
library(officer)
library(dplyr)
myft <- flextable(head(mtcars),
col_keys = c("am", "carb", "gear", "mpg", "drat" ))%>%
theme_vanilla()%>%
merge_v(j = c("am"))%>%border(border.bottom = fp_border(style = "solid", width=2), i=c(3,6), part="body")
myft
A much simpler solution is to add a column that indicates which rows need a bottom border and then add an hline()
with a row selection that uses that value. That helper selection can be kept out of the table by only selecting the columns you want to show in the original flextable specification using col_keys
.
library(tidyverse)
library(flextable)
your_flextable = tibble(
col_group = rep(letters[1:3], each = 3),
the_value = rnorm(length(col_group))
) %>%
group_by(col_group) %>%
mutate(
is_last_val_in_group = row_number() == max(row_number())
) %>%
flextable(col_keys = c('col_group', 'the_value')) %>%
merge_v(j = 'col_group') %>%
hline(i = ~is_last_val_in_group == TRUE, border = fp_border()) %>%
fix_border_issues()