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

Let huxtable use markdown #885

Closed
hughjonesd opened this issue May 1, 2021 · 3 comments · Fixed by #924
Closed

Let huxtable use markdown #885

hughjonesd opened this issue May 1, 2021 · 3 comments · Fixed by #924

Comments

@hughjonesd
Copy link
Contributor

hughjonesd commented May 1, 2021

Since version 5.0.0, huxtable supports markdown within table cells with the set_markdown() functionality:

set_markdown(ht, rows, cols)
# or the shortcut
set_markdown_contents(ht, rows, cols, "**bold** *italic*")

Describe the solution you'd like

as_hux_table should set strip_md_bold = FALSE by default, and probably this option could be deprecated. Cells containing markdown should have set_markdown(TRUE) set on them.

Additional context

I'd make a pull request myself, but I have to be honest - I find the gtsummary code really hard to get my head around! I suspect you could do this much faster than I can, but if you don't have time, tell me and I will try.

@ddsjoberg
Copy link
Owner

ddsjoberg commented May 1, 2021

Can you give an example how the markdown function is used? How would I go about allowing markdown for the header rows in the example below?

trial %>%
  select(age) %>%
  tbl_summary() %>%
  as_tibble() %>%
  huxtable::as_huxtable(add_colnames = FALSE) %>%
  huxtable::insert_row(after = 0, 
                       label = "**Characteristic**", 
                       stat_0 = "**N = 200**") %>%
  huxtable::set_markdown(row = 1)

@hughjonesd
Copy link
Contributor Author

hughjonesd commented May 1, 2021

Last line should be set_markdown(1, huxtable::everywhere, TRUE). I also wouldn't use names for the cells you insert, just in case any future version has an explicit e.g. label argument.

@ddsjoberg
Copy link
Owner

Thanks! I'll add it to the list of things to do.

Some notes for myself.... I think all I need to do is add the one line above to the huxtable calls. When there is a spanning header, then I'll likely need to include row = 1:2

library(gtsummary)

tbl <- 
  trial %>%
  select(age, trt) %>%
  tbl_summary(by = trt) %>%
  as_hux_table(strip_md_bold = FALSE) %>%
  huxtable::set_markdown(row = 1, col = huxtable::everywhere, value = TRUE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants