After updating flextable from 0.6.10 to 0.7.3 I can't add footers that apply to the same row but multiple columns any longer. Simple reproducible example where I'd like to mark all "N/A" values in columns "p" and "p_adj" with the same footer:
p_values <- c("0.01", "N/A", "0.02", "N/A", "0.03", "N/A")
df <- data.frame(mean = seq(1,6),
p = p_values,
p_adj = p_values)
df |>
flextable() |>
footnote(i = ~ p == "N/A",
j = c("p", "p_adj"),
value = flextable::as_paragraph("Sample size too low"),
ref_symbols = "a",
part = "body")
This results in an error:
Error in data.frame(i = i, j = j) :
arguments imply differing number of rows: 3, 2
Application to only one column works fine:
df |>
flextable() |>
footnote(i = ~ p == "N/A",
j = c("p"),
value = flextable::as_paragraph("Sample size too low"),
ref_symbols = "a",
part = "body")
I have tried for hours, but can't come up with a good solution. Simple solutions that don't work:
- Applying a footnote separately for each column. This duplicates the footnote line below the table.
- Duplicating the row selection vector.
aka:
df |>
flextable() |>
footnote(i = ~ rep(p == "N/A", 2),
j = c("p", "p_adj"),
value = flextable::as_paragraph("Sample size too low"),
ref_symbols = "a",
part = "body")
This results in the error below:
Error in get_rows_id(x[[part]], i) :
invalid row selection: length(i) [12] != nrow(dataset) [6]
Does anyone have an idea how to work with the updated flextable::footnote() function in this circumstance?