Calling `colformat_md()` on header rows removes labels?
Closed this issue ยท 12 comments
Hello! I recently came across your package, and it's awesome! Thank you for your dev work.
I maintain a package called gtsummary that creates summary tables that can be exported as a flextable. I use markdown syntax in the headers that is supported by other output types gt and huxtable. I would like to utilize your package to add support for the markdown syntax in the headers of the flextables too.
I've played around with the ftExtra::colformat_md(part = "header")
function to try and use markdown in the header.
Is it possible to utilize the function in this way (aka on column header labels) to use markdown bold syntax in the header, or do I need to rename the underlying columns to use this function on the headers?
Thank you!
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.2'
tbl1 <-
trial %>%
select(age, trt) %>%
tbl_summary(by = trt) %>%
as_flex_table(strip_md_bold = FALSE)
tbl2 <- ftExtra::colformat_md(tbl1, part = "header")
Created on 2022-04-16 by the reprex package (v2.0.1)
Thank you for opening the issue.
This is indeed the limitation from the current implementation related to #61.
colformat_md
needs be called before the content of data frame is modified by flextable because ftExtra::colformat_md
considers tbl1$header$dataset
as the content of header.
ftExtra::colformat_md
should rather look at tbl1$header$content$content$data
.
I will give a try to improve, but am not sure when.
Thank you so much for the response!
In the meantime, I don't think it would be too much work on my end to use formatted column names instead of using flextable column header labels.
Quick update: I began to make the update above (using the column names instead of using the column labels defined in felxtable). BUT, I realized this won't work with the spanning headers. Is there a way to make the additional headers use markdown syntax?
Thanks for the update. The fix on #61 will also support the spanning headers.
I also have started working on this issue and #61 this morning, and I think I guess I can make things happen in this week.
Except for a few edge cases, my initial improvements already work (not yet pushed).
tibble::tibble(
`x_**b**` = c("**bold**", "*italic*"),
y = c("^superscript^", "~subscript~"),
z = c("***~ft~^Extra^** is*", "*Cool*")
) %>%
as_flextable() %>%
span_header(sep="_") %>%
colformat_md(part = "all")
That is fantastic! Thank you!
Wow, it's beautiful! You're so good! ๐
@ddsjoberg Would you try remotes::install_github("atusy/ftExtra#72")
? This should solve the issue.
@atusy ! This is amazing! I did some testing, and everything seems to work perfectly.
I think I'll implement in gtsummary with the following lines. If you have any suggestions, please do let me know!
library(gtsummary)
packageVersion("gtsummary")
#> [1] '1.5.2'
packageVersion("ftExtra")
#> [1] '0.3.0.9999'
tbl <-
trial %>%
select(marker, trt) %>%
tbl_summary(by = trt) %>%
modify_spanning_header(all_stat_cols() ~ "***Treatment***\nsecond line") %>%
modify_footnote(label = "Testing *italic* and **bold**") %>%
as_flex_table(strip_md_bold = FALSE) %>%
ftExtra::colformat_md(part = "header", md_extensions = "+hard_line_breaks")
Created on 2022-04-18 by the reprex package (v2.0.1)
Thank you for the wonderful package! I am planning a gtsummary release in the next couple of weeks. Do you have an idea of when you'll push these updates to CRAN? I think it'll be great to include them!
Thank you for the quick reaction! I am happy to hear the nice result!
About the CRAN release, I will plan in this week.
Let me wait a couple of days for the response from @joelnitta on #61.
If he is silent, I will release anyway.
Thanks for the fix! I will try this tomorrow.
Thanks!