Display a tabular object using HTML.

Description

This is similar to print.tabular, but it inserts the code to display the table in an HTML table.

Usage

1
2
3
4
## S3 method for class 'tabular'
html(object, file = "", options = NULL, 
                       id = NULL, append = FALSE, ...)
writeCSS(CSS = htmloptions()$CSS, id = NULL)

Arguments

object

The tabular object.

file

A filename or connection to which to write the HTML code, or "" to write to the standard output.

options

A list of options to set for the duration of the call.

id

A unique identifier to set for this table and the associated CSS style, or NULL, for no id.

append

If TRUE, opens file for appending (if it is a filename rather than a connection).

...

Settings for default formatting. See Details below.

CSS

A character vector to use as CSS.

Details

The html() method produces HTML output suitable for inclusion in an HTML page.

In HTML, it is mainly the CSS style sheet that determines the look of the table. When formatting a table, html.tabular sets the CSS class according to the table's Justify setting; justifications of c("l", "c", "r") are translated to classes c("left", "center", "right") respectively; other strings will be passed through and used directly as class names. If the id value is not NULL, then it will be used as the CSS id selector when searching for a style. See table_options for a number of options that control formatting, including the default style sheet.

Value

The html() method writes the HTML code to file and returns a list containing that name, with class "html".

See Also

print.tabular, latex.tabular, html, htmloptions

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
X <- rnorm(125, sd=100)
Group <- factor(sample(letters[1:5], 125, rep=TRUE))

tab <- tabular( Group ~ (N=1)+Format(digits=2)*X*((Mean=mean) + Heading("Std Dev")*sd) )

save <- table_options()
table_options(rowlabeljustification="c")

f <- tempfile(fileext=".html")
con <- file(f, "wt")

html(tab, con, options=htmloptions(head=TRUE, table=FALSE))

writeLines("<p>This table has pad = FALSE.  The centered numbers look
sloppy.<br>", con)

html(tab, con, options=htmloptions(head=FALSE, table=TRUE, pad=FALSE))

writeLines("<p>This table has pad = FALSE and justification=\"r\".
The justification makes the columns of numbers look all right (except
for the hyphens used as minus signs), but they are placed poorly
relative to the labels.<br>", con)

html(tab, con, options=htmloptions(head=FALSE, table=TRUE, pad=FALSE, justification="r"))

writeLines("<p>This one has pad = TRUE. It looks best, but if you cut
and paste, the spacing characters may cause problems.<br>", con)

html(tab, con, options=htmloptions(head=FALSE, table=TRUE, pad=TRUE))

table_options(save)
close(con)
browseURL(f)