Learn R Programming

textutils (version 0.1-9)

toHTML: Convert R Objects to HTML

Description

Convert an R object to an HTML snippet.

Usage

toHTML(x, ...)

# S3 method for data.frame toHTML(x, …, row.names = FALSE, class.handlers = list(), col.handlers = list())

Arguments

x

an object

arguments passed to methods

row.names

logical

class.handlers

a list of named functions

col.handlers

a list of named functions

Value

a character vector

Details

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 arbitrary R object and return an HTML snippet that can be placed in reports (i.e. in the same spirit as toLatex). By contrast, the purpose of toHTML in tools is to provide a whole HTML document.

In the data.frame method supports 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.

See Also

toLatex

Examples

Run this code
# NOT RUN {
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...  ]
## <tr>   <th>a</th>   <th>b</th> </tr>
## <tr> <td>100</td><td>-2.3</td> </tr>
## <tr> <td>200</td><td>-0.1</td> </tr>
## <tr> <td>300</td><td>-2.8</td> </tr>

# }

Run the code above in your browser using DataLab