qable {qwraps2} | R Documentation |
Qable: an extended version of knitr::kable
Description
Create a simple table via kable
with row
groups and rownames similar to those of latex
from the
Hmisc package or htmlTable
from the htmlTable
package.
Usage
qable(
x,
rtitle = "",
rgroup = numeric(0),
rnames = rownames(x),
cnames = colnames(x),
markup = getOption("qwraps2_markup", "latex"),
kable_args = list(),
...
)
Arguments
x |
|
rtitle |
a row grouping title. See Details. |
rgroup |
a named numeric vector with the name of the row group and the
number of rows within the group. |
rnames |
a character vector of the row names |
cnames |
column names |
markup |
the markup language to use expected to be either "markdown" or "latex" |
kable_args |
a list of named arguments to send to
|
... |
pass through |
Details
rtitle
can be used to add a title to the column constructed by the
rgroup
and rnames
. The basic layout of a table generated by
qable
is:
rtitle | cnames[1] | cnames[2] |
rgroup[1] | ||
rnames[1] | x[1, 1] | x[1, 2] |
rnames[2] | x[2, 1] | x[2, 2] |
rnames[3] | x[3, 1] | x[3, 2] |
rgroup[2] | ||
rnames[4] | x[4, 1] | x[4, 1] |
rnames[5] | x[5, 1] | x[5, 1] |
Passing arguments to link[knitr]{kable}
is done via the list
kable_args
. This is an improvement in 0.6.0 to address arguments with
different use between qable and kable but the same name, notably
format
. Within the print method for qwraps2_qable
objects,
some default arguments for knitr::kable are created.
Defaults if the named element of kable_args
is missing:
kable_args$format
will be "latex" if markup = "latex"
and will
be "pipe"
if markup = "markdown"
.
kable_args$escape = !(markup = "latex")
kable_args$row.names
defaults to FALSE
kable_args$col.names
defaults to colnames(x)
Value
qable
returns a qwraps2_qable
object that is just a character matrix with
some additional attributes and the print method returns, invisibly, the
object passed to print.
See Also
summary_table
, for an example of build a data summary table.
For more detail on arguments you can pass via kable_args
look at the
non-exported functions form the knitr package knitr:::kable_latex
,
knitr:::kable_markdown
, or others.
Examples
data(mtcars)
x <- qable(mtcars)
x
qable(mtcars, markup = "markdown")
# by make
make <- sub("^(\\w+)\\s?(.*)$", "\\1", rownames(mtcars))
make <- c(table(make))
# A LaTeX table with a vertical bar between each column
qable(mtcars[sort(rownames(mtcars)), ], rgroup = make)
# A LaTeX table with no vertical bars between columns
qable(mtcars[sort(rownames(mtcars)), ], rgroup = make, kable_args = list(vline = ""))
# a markdown table
qable(mtcars[sort(rownames(mtcars)), ], rgroup = make, markup = "markdown")
# define your own column names
qable(mtcars[sort(rownames(mtcars)), ],
rgroup = make,
cnames = toupper(colnames(mtcars)),
markup = "markdown")
# define your own column names and add a title
qable(mtcars[sort(rownames(mtcars)), ],
rtitle = "Make & Model",
rgroup = make,
cnames = toupper(colnames(mtcars)),
markup = "markdown")