as_kable.tablet {tablet} | R 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),
secondary = TRUE
)
Arguments
x |
|
... |
passed to |
booktabs |
passed to |
escape |
passed to |
escape_latex |
a function to pre-process column names and content if 'escape' is FALSE (e.g., manual escaping, latex only); default |
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 |
linebreak |
whether to invoke |
align |
passed to |
double_escape |
passed to |
linebreaker |
passed to |
pack_rows |
named list passed to |
secondary |
passed to escape_latex |
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)
# 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