as_kable.tablet: Coerce Tablet to Kable

as_kable.tabletR Documentation

Coerce Tablet to Kable

Description

Renders a tablet. Calls kbl and implements special features like grouped columns.

Usage

## S3 method for class 'tablet'
as_kable(
  x,
  ...,
  booktabs = TRUE,
  escape = FALSE,
  escape_latex = tablet::escape_latex,
  escape_html = function(x, ...) x,
  variable = " ",
  col.names = NA,
  linebreak = TRUE,
  align = "c",
  double_escape = FALSE,
  linebreaker = "\n",
  pack_rows = list(escape = escape)
)

Arguments

x

tablet

...

passed to kbl

booktabs

passed to kbl

escape

passed to kbl; defaults FALSE to allow header linebreaks

escape_latex

a function to pre-process column names and content if 'escape' is FALSE (e.g., manual escaping, latex only); default escape_latex

escape_html

a function to pre-process column names and content if 'escape' is FALSE (e.g., manual escaping, html only)

variable

a column name for the variables

col.names

passed to kbl after any linebreaking

linebreak

whether to invoke linebreak for column names

align

passed to linebreak for column names

double_escape

passed to linebreak for column names

linebreaker

passed to linebreak for column names in latex; for html, newline is replaced with <br>

pack_rows

named list passed to pack_rows for finer control of variable names

Details

See also tablet.data.frame. Column _tablet_name must inherit 'character' and by default (in a latex render context) its values will eventually be processed by escape_latex. Thus, if _tablet_name is of class 'latex' it will be handled by method escape_latex.latex (which tries not to re-escape metacharacters).

Value

like kbl

Examples

library(boot)
library(dplyr)
library(magrittr)
library(haven)
library(yamlet)
library(spork)
melanoma %>%
  select(-time, -year) %>%
  mutate(sex = factor(sex), ulcer = factor(ulcer)) %>%
  group_by(status) %>%
  tablet %>%
  as_kable

x <- system.file(package = 'tablet', 'shiny-examples/mesa/data/adsl.sas7bdat')
x %<>% read_sas %>% data.frame
decorations(x) # note weight in pounds
x %<>% mutate(weight = signif(digits = 3, weight * 2.2))

# calculate BMI by assuming all males are 1.75 m, all females 1.63 cm
x %<>% mutate(height = ifelse(sex == 'F', 1.63, 1.75))
x %<>% mutate(bmi = signif(digits = 3, weight / (height^2)))
x %<>% filter(saffl == 'Y')
x %<>% select(trt01a, age, sex, weight, bmi)
x %<>% redecorate('
trt01a: [ Treatment, [ Placebo, TRT 10 mg, TRT 20 mg ]]
age:    [ Age, year ]
sex:    [ Sex, [ Female: F, Male: M ]]
weight: [ Body Weight, kg ]
bmi:    [ Index_body mass, kg/m^2 ]
')
x %<>% resolve
x %<>% group_by(trt01a)

x %>% tablet %>% as_kable

# supply default and unit-conditional latex titles
x %<>% modify(title = concatenate(as_latex(as_spork(c(.data$label)))))
x %<>% modify(
age, weight, bmi,
  title = concatenate(
    sep = '',  # default ok in pdf
    as_latex(
      as_spork(
        c(.data$label, ' (', .data$units, ')')
      )
    )
  )
)
x %>% tablet %>% as_kable

tablet documentation built on April 30, 2022, 1:07 a.m.