Learn R Programming

Kmisc (version 0.5.0)

makeHTMLTable: Make HTML Table from R 'table-like' Object

Description

Function for making HTML tables from an R 'table-like' object; ie, a data.frame or a matrix. It simply parses the item as an HTML table.

Usage

makeHTMLTable(x, attr, row.spans = 0, col.spans = 0, use.row.names = FALSE, use.col.names = FALSE, clean = TRUE, replace.periods = TRUE)

Arguments

x
the data.frame / matrix you want to convert to an HTML table.
attr
attributes to be passed to the
tag, as raw HTML.
row.spans
a matrix specifying desired row.spans, for largers cells.
col.spans
a matrix specifying desired column spans, for larger cells.
use.row.names
if you submit an object with row names, use those names in construction of the table.
use.col.names
if you submit an object with column names, use those names in construction of the table.
clean
boolean. if TRUE, we print all numeric values with 4 digits. Alternatively, we can pass a format specifier as used by sprintf.
replace.periods
replace periods with spaces?

Details

The row.spans and col.spans argument can be specified as a matrix to set the row or column span of a certain cell to be >1, if desired. See pxt for an example implementation. It will also handle 'boxes', e.g. cells with both rowspan and colspan > 1.

Note that the default behavior is to 'clean' numeric input; this prints numeric values with a maximum of four digits; ie, through the "%.4G" format specifier. Alternatively, you can use a format specifier (as used in sprintf) to ensure numbers are formatted and displayed as desired.

Examples

Run this code
dat <- data.frame( apple=c(1.2150125, 2, 3), banana=c("a", "b", "c") )
makeHTMLTable( dat )

Run the code above in your browser using DataLab