jenniferthompson / JTHelpers

A package of helper functions for my own frequent use.
0 stars 0 forks source link

Add function to make rms_model_results() into a huxtable #3

Open jenniferthompson opened 6 years ago

jenniferthompson commented 6 years ago

Originally written for DelDepLTCI

## -- Function to make huxtable from rms_model_results() df + col headers ------
make_modresults_ht <- function(resultsdf){
  ht <- resultsdf %>%
    hux() %>%
    ## Align variable name to left, all other columns to right
    set_align(row = everywhere, col = everywhere, byrow = TRUE,
              value = c("left", rep("right", ncol(resultsdf) - 1))) %>%
    ## Set p-value column to three decimal places by default
    set_number_format(row = everywhere, col = 7, value = 3) %>%
    ## Bold column headers, add line after first row
    set_bold(row = 1, col = everywhere, TRUE) %>%
    set_bottom_border(row = 1, col = everywhere, value = 1) %>%
    ## Gray out all info except the row for history of depression, our main
    ## exposure of interest
    set_text_color(
      row = grep("^hx\\.depression$", resultsdf$label, invert = TRUE),
      col = everywhere,
      value = "#838383"
    ) %>%
    ## Table should take up 90% of document width
    set_width(0.9)
}
jenniferthompson commented 6 years ago

Actually I've been using kableExtra more lately... [why not have both? gif]