Home > Software engineering >  Adding a footer to flextable without specifying cells
Adding a footer to flextable without specifying cells

Time:08-17

I'd like to add a footnote to a flextable. Ideally, I don't want to add a ref_symbol but not sure if that's possible, but even when I try to do it with a ref_symbol in the first cell of the header, I'm getting an error:

df = structure(list(Centre_group = c("NA or other", "NA or other", 
"North", "North", "South east", "South east", "South west"), 
    reliable_use_info = c(FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, 
    TRUE), n = c(126L, 135L, 140L, 364L, 1065L, 508L, 1126L)), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -7L), groups = structure(list(
    Centre_group = c("NA or other", "North", "South east", "South west"
    ), .rows = structure(list(1:2, 3:4, 5:6, 7L), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -4L), .drop = TRUE))

flextable(df)%>%
footnote(i=1,j=1, part= "header", value= as_paragraph("My footnote")

Error:

Error in `[<-`(`*tmp*`, i, j, value = value) : subscript out of bounds

CodePudding user response:

You can use add_footer_lines():

flextable(head(iris)) |>
  add_footer_lines("My footnote")

enter image description here

  • Related