nutterb / pixiedust

Tables So Beautifully Fine-Tuned You Will Believe It's Magic.
180 stars 18 forks source link

formatting of text columns for rmarkdown to html #100

Closed HelenaEdlund closed 6 years ago

HelenaEdlund commented 7 years ago

I am using dust to print data frames to latex and rmarkdown. The first column is a text column for which I want to have some formating instructions included. E.g. c("Age ($years$)", "Body weight ($kg$)", "Body height ($cm$)", "Body mass index ($kg/m^{2}$)", "eGFR ($mL/min/1.73m^{2}$)", "Serum creatinine ($mg/dL$)")

When pushing to latex I get what I expected: latex

But when using rmarkdown (to html) the formatting instructions are ignored and it prints as is. I tried using rmarkdown notation for the superscript to see if that was causing the issue but get the same result: markdown

Any suggestions?

Thanks, Helena

nutterb commented 7 years ago

You have a real knack for finding weak spots in packages! :)

I know what causes this. The HTML code gets wrapped by htmltools::htmlPreserve. I've had problems with certain characters, usually < and > being translated to HTML entities when I didn't want them to be. To try and address your specific case, I made a branch with an experimental method to disable the preservation. Feel free to try

devtools::install_github("nutterb/pixiedust", ref = "noPreservatives")

and then use

data.frame(
  Characteristics = c("Age ($years$)", 
                      "Body weight ($kg$)", 
                      "Body height ($cm$)",
                      "Body mass index ($kg/m^{2}$)", 
                      "eGFR ($mL/min/1.73m^{2}$)", 
                      "Serum creatinine ($mg/dL$)"),
  stringsAsFactors = FALSE) %>% 
  dust(float = FALSE,
       html_preserve = FALSE) %>%
  medley_bw()

It's working with just the one column. I don't know what else is in your table, and I honestly have no idea what other side effects this might have on the HTML output.

nutterb commented 6 years ago

This will be included in 0.8.2. currently available via

devtools::install_github("nutterb/pixiedust", ref = "devel")