knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(magrittr)

options(huxtable.knit_print_df = FALSE)
library(huxtable)
mydf <- data.frame(`Heading 1` = 1:5, foo = letters[1:5], short = rnorm(5))

This should print as a standard data frame:

mydf 

This should be a nice hux:

options(huxtable.knit_print_df = TRUE)
mydf

The next one should be a colourful hux:

mytheme <- function (ht) {
  ht %>% set_all_border_colors("green") %>% set_all_borders(0.4) %>% set_background_color(evens, odds, "pink")
}
options(huxtable.knit_print_df_theme = mytheme)

mydf

Back to plain theme

options(huxtable.knit_print_df_theme = NULL)

mydf$date <- as.character(as.Date(rep("2005-01-12", 5)))
mydf$integer <- 1L:5L
mydf$has_nums <- paste(letters[1:5], 1:5, letters[5:1])
mydf$long <- substr(stringi::stri_rand_lipsum(5), 1, sample(20:50, 5))
mydf

# compare with basic default
as_hux(mydf, add_colnames = TRUE) %>% set_all_borders(0.4) %>% set_position('left')


hughjonesd/huxtable documentation built on Feb. 17, 2024, 12:20 a.m.