0

Once a footnote has been set via add_footnote it seems like its hard to get rid of again.

library(magrittr)
library(huxtable)

jams <- hux(
  Type  = c("Strawberry", "Raspberry", "Plum"),
  Price = c(1.90, 2.10, 1.80)
) %>% add_footnote("Tasty stuff!")

One solution I tried is this:

head(jams, -1)

Unfortunately, the line at the bottom of the huxtable remains. What I would like is a solution which returns a huxtable as if the footnote had never been set.

EDIT: The code below will also remove the line:

jams <- head(jams, -1)
attributes(jams)$tb_borders$thickness[nrow(attributes(jams)$tb_borders$thickness), ] <- 0

I'm not sure how robust this is though.

EDIT: One issue is that if you use this to remove a footnote which was never set then you remove a line of data.

Patrick
  • 742
  • 7
  • 19

1 Answers1

1

If you want to get rid of the border, just use the relevant function:

jams <- hux(
  Type  = c("Strawberry", "Raspberry", "Plum"),
  Price = c(1.90, 2.10, 1.80)
) %>% add_footnote("Tasty stuff!")

head(jams, -1) %>% set_bottom_border(final(1), everywhere, 0)
dash2
  • 2,024
  • 6
  • 15
  • Is there a generic way to check if a footnote exists to make the removal of the last line conditional or do I "just have to know" that a footnote was set? – Patrick Aug 02 '22 at 10:38
  • just have to know. A footnote is just a cell. You could check for it manually, for example by looking at `colspan()` or by setting an attribute on the table when you add the footnote. – dash2 Aug 02 '22 at 17:46
  • I like the attribute idea. Could that be a feature request for an upcoming package update? – Patrick Aug 03 '22 at 06:34
  • 1
    I think it would probably need to be part of a more general rework. You're welcome to file a feature request explaining what you want and why it would be more generally useful. – dash2 Aug 04 '22 at 11:45