Learn R Programming

Kmisc (version 0.2.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 = NULL, row.spans = 0,
    col.spans = 0, use.row.names = FALSE,
    use.col.names = FALSE, clean = FALSE,
    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, rounds all numeric values to 2 decimal places for better printing
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', eg cells with both rowspan and colspan > 1.

Note that the default behavior is to 'clean' your data; this rounds numeric output to two decimal places so it prints more nicely.

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