| as_gridtable | R Documentation |
Coerces to "gridtable", i.e. the Pandoc construct "grid table" Generic,
with method as_gridtable.character.
as_gridtable(x, ...)
x |
object |
... |
passed arguments |
see methods
Other gridtable:
as.data.frame.gridtable(),
as_calibrated(),
as_calibrated.data.frame(),
as_gridtable.character(),
as_gridtable.data.frame(),
kbl(),
kbl.calibrated(),
kbl.default(),
kbl.gridtable(),
print.gridtable()
# as_gridtable() lets you create and render small data tables on-the-fly.
library(magrittr)
library(tablet)
library(yamlet)
library(kableExtra)
'+--+--+--+
|study | subjects | doses |
+==+==+==+
| 001 | 20 | 5 mg, 10 mg |
+--+--+--+
| 002 | 40 | 5 mg, 10 mg |
| | | 15 mg, 20 mg, 30 mg |
+--+--+--+' %>%
as_gridtable
# We see that as_gridtable cleans up our Pandoc grid table markdown.
# We copy it here and render it with kableExtra::kbl().
'
+-------+----------+---------------------+
| study | subjects | doses |
+=======+==========+=====================+
| 001 | 20 | 5 mg, 10 mg |
+-------+----------+---------------------+
| 002 | 40 | 5 mg, 10 mg |
| | | 15 mg, 20 mg, 30 mg |
+-------+----------+---------------------+
' %>%
as_gridtable %>%
as.data.frame(scale = 0.9) %>% # or: options(tablet.gridtable.scale = 0.9)
decorations
# We see that a gridtable when converted to data.frame
# has scalable column width attributes.
# Widths are controlled by longest line of text, including column name.
# kbl will try to honor widths.
# kbl() will call as.data.frame() implicitly if you pass a gridtable:
'
+-------+----------+---------------------+
| study | subjects | doses |
+=======+==========+=====================+
| 001 | 20 | 5 mg, 10 mg |
+-------+----------+---------------------+
| 002 | 40 | 5 mg, 10 mg |
| | | 15 mg, 20 mg, 30 mg |
+-------+----------+---------------------+
' %>%
as_gridtable %>%
kbl(
label = "studies",
booktabs = TRUE,
caption = "Study Characteristics"
) %>%
kable_styling(font_size = 9) %>%
footnote(
threeparttable = TRUE,
general_title = "",
general = "For more details, see study protocols."
)
# We can start with a data.frame:
data.frame(
study = c('001','002'),
subjects = c(20, 40)
) %>%
as_gridtable
# We can integrate decorations:
'
+-------+----------+
| study | subjects |
+=======+==========+
| 001 | 20 |
+-------+----------+
| 002 | 40 |
+-------+----------+
' %>%
as_gridtable %>%
as.data.frame %>%
decorate('
study: [ Study, [ ST001: "001", ST002: "002" ]]
subjects: [ N Subjects ]
') %>%
resolve %>%
kbl(
label = "studies",
booktabs = TRUE,
caption = "Study Characteristics"
) %>%
kable_styling()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.