
Last chance! 50% off unlimited learning
Sale ends in
Convert an R object to an HTML snippet.
toHTML(x, ...)# S3 method for data.frame
toHTML(x, ...,
row.names = FALSE,
col.names = TRUE,
class.handlers = list(),
col.handlers = list(),
replace.NA = NULL,
td.id = FALSE)
a character vector
an object
arguments passed to methods
logical (whether to include row names or not) or string (the column name used for the row-names column)
logical (whether to include column names or not) or character (specify column names)
a list of named functions. See Examples.
a list of named functions. See Examples.
NULL
(do nothing), or a string that replaces
all NA values. NA values are noted before
any handlers are called.
logical
Enrico Schumann
There exists toHTML
methods in several packages,
e.g. in tools or XML. Package R2HTML has
a HTML
generic.
The ‘semantics’ of this function may differ from
other implementations: the function is expected to take an
arbitrary R object and return an HTML snippet
that can be placed in reports, i.e. the function works in
the same spirit as toLatex
. By contrast, the
purpose of toHTML
in tools is to
provide a whole HTML document.
The data.frame
method has two handlers
arguments: these may store helper functions for formatting
columns, either of a specific name (col.handlers
) or
of a specific class(class.handlers
). The functions in
col.handlers
are applied first; and the affected
columns are not touched by class.handlers
. See
Examples.
If td.id
is TRUE
, all data cells in the table
(i.e. td elements) gain an id
-attribute of the form
td_<row>_<col>
.
x <- data.frame(a = 1:3, b = rnorm(3))
cat(toHTML(x,
col.handlers = list(b = function(x) round(x, 1)),
class.handlers = list(integer = function(x) 100*x)))
## [ pretty-printed... ]
## a b
## 100-2.3
## 200-0.1
## 300-2.8
Run the code above in your browser using DataLab