Learn R Programming

qwraps2 (version 0.5.2)

qable: Qable: an extended version of knitr::kable

Description

Create a simple table via kable with row groups and rownames similar to those of hmisc::latex or htmlTable::htmlTable.

Usage

qable(
  x,
  rtitle,
  rgroup,
  rnames = rownames(x),
  cnames = colnames(x),
  markup = getOption("qwraps2_markup", "latex"),
  ...
)

Arguments

x

matrix or data.frame to be turned into a qable

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. sum(rowgroup) == nrow(x).

rnames

a character vector of the row names

cnames

column names

markup

the markup language to use, passed to the format argument of knitr::kable.

...

additional arguments passed to knitr::kable

Value

a character vector of the formatted numbers

Details

qable is used as the printing method for qwraps2_summary_table objects. Check the vignettes for examples on building data summary tables.

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]

It should be noted that escape = !(markup == "latex") is passed to kable.

See Also

kable

summary_table, for an example of build a data summary table, i.e., a “Table 1”.

For more detail on arguments you can pass to ... look at the non-exported functions form the knitr package knitr:::kable_latex, knitr:::kable_markdown, or others.

Examples

Run this code
# NOT RUN {
data(mtcars)
qable(mtcars)
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, 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")

# }

Run the code above in your browser using DataLab