Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colwidth=all to add_footer_row() #620

Closed
wants to merge 1 commit into from

Conversation

DanChaltiel
Copy link
Contributor

Hi David,

Most often, when I want to add a footer row, it is mostly to add an addendum to my table so I want a single value that takes all the width.
Also, it can be tedious to count the number of columns in big tables, so filling colwidth is a bit annoying for a thing that could be automated.

I hereby propose to add a colwidth="all" shortcut syntax to fill this need:

ft_1 <- flextable(head(mtcars))
add_footer_row(ft_1, values="I am rich too", top=FALSE, colwidths="all")

On second thought, maybe this should be the default behavior instead of numeric(0), so that when value is of length 1 colwidths is set to the whole table width. This way you don't change the interface, only the default.
Let me know what you think and I'll change my PR if needed (and considered).

@davidgohel
Copy link
Owner

You can use add_footer_lines(). See https://ardata-fr.github.io/flextable-book/header-and-footer.html#add-lines-of-text and https://davidgohel.github.io/flextable/reference/add_header_lines.html

ft_1 <- flextable(head(iris))
ft_1 <- add_footer_lines(ft_1,
  values = c("blah 1", "blah 2")
)
ft_1
Capture d’écran 2024-03-29 à 17 23 19
ft_2 <- flextable(head(iris))
ft_2 <- add_footer_lines(ft_2,
  values = as_paragraph(
    as_chunk("yeahhh", props = fp_text_default(color = "orange")),
    " ",
    minibar(value = 5, max = 10, barcol = "orange", bg = "black", height = .15)
  )
)
ft_2
Capture d’écran 2024-03-29 à 17 23 54

@davidgohel
Copy link
Owner

Note that to know the number of columns, there is also a function named ncol_keys()

@DanChaltiel
Copy link
Contributor Author

It seems that I have the habit of proposing already existing features, sorry for that!

However, in that specific case, I think my point stands, as when there is only one line to add, both functions could be used.

Also, I think there should be only one help file for both functions as they are very similar and serve the same purpose. I think add_footer_lines() is just a helper around add_footer_rows(). The argument order is a bit confusing though.

The documentation is so big that only a few people can know all the functions available. I rely heavily on the very logical function naming and the autocomplete. Here, "rows" feels a bit more natural than "lines" so I stop looking after finding add_footer_rows(). If they were in the same help file I would have noticed add_footer_lines().

@davidgohel davidgohel closed this Apr 1, 2024
Repository owner locked as too heated and limited conversation to collaborators Apr 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants