bdCharacter
representing a vector, a
bdVector
, a matrix, a data.frame, or a
bdFrame
as an HTML table.
The vector or
bdVector
will contain one string for each line of HTML.
This may be written to a file by specifying the
file
argument,
or may be manipulated and later written to a file using the
write
function.
html.table(x, file="", append=F, main="", center=F, html.tag=F, table.attributes = "BORDER", column.attributes=<<see below>>, cell.attributes="", row.header.attributes="ALIGN_RIGHT", row.header.column.attributes="", data.column.attributes="", ...)
bdVector
, matrix, data.frame, or
bdFrame
to be placed in table. May also be a list
containing vectors,
bdVector
s, matrices, data frames, or
bdFrame
s, in which case multiple
tables will be generated.
TRUE
,
html.table
adds to an existing file; otherwise, it
creates a new file (destroying any existing file by that name). Only relevant
if
file
is specified.
x
is not a list, and as a header
if
x
is a list.
TRUE
, the result is wrapped in a CENTER tag. This centers the
table or tables on the page.
TRUE
, the result is wrapped in an HTML tag. This is needed by
some browsers for the file to be recognized as HTML.
x
.
nrow(x)
long.
bdVector
ncol(x)
long or a scalar.
If scalar, it is repeated to be
ncol(x)
long.
format
. These are arguments such as
digits
, which are
useful for formatting the data.
file==""
, a vector of character strings or a or
bdCharacter
is returned, with each string containing one line of HTML.
Otherwise, the HTML is written to the specified
file, and the name of the file is returned invisibly.
file!=""
, the HTML is written to the specified file.
"Attributes" can control the color and size of cells in the table, as well as fonts and other things. Typical ones include width="10%" (this column should be 10% the width of the entire table), bgcolor="red" (the background of this cell, column, or row should be red), and align="center" (center data in this cell, column, or row).
# Simple examples html.table(round(cor(state.x77), digits=4), file="my.htm") html.table(catalyst, file="my.htm") # Multiple matrices my.results <- list("Regression Coefficients"=round(coef(lm(Mileage~Weight, fuel.frame)),digits=4), "Correlations"=round(cor(fuel.frame[,1:3]), digits=4)) html.table(my.results, file="my.htm") # Show correlation matrix with high correlations in red # and put no borders on anything. z <- cor(state.x77) html.table(round(z,2), file="my.htm", table.attributes = "", cell.attributes = array(dim = dim(z), paste("bgcolor=", ifelse(abs(z)>.7 & abs(z)<1.0, "red", "white")))) # make all data cells the same width (allowing 30% of width for row headers), # center data cell entries, # and left justify the row headers html.table(round(z,2), file="my.htm", cell.attributes="align=center", data.column.attributes=paste("width=\"",70/ncol(z),"%\"",sep=""), row.header.attributes="align=left") # Time series my.lynx <- lynx names(my.lynx) <- time(lynx) html.table(my.lynx,file="my.htm",main="Lynx Data") # Use write() to add other headings or comments write("<H3> S-PLUS Code for the above </H3> <P> Put code here </P>", file="my.htm", append=T) # Embedding preformatted output sink("my.htm") cat(sep="", "<", "H3", ">", " Linear Model Results ", "<", "/H3", ">", "\n") cat(sep="", "<", "PRE", ">") summary(lm(Mileage~Weight, fuel.frame)) cat(sep="", "<", "/PRE", ">") sink() # Embedding a plot in S-PLUS for Windows sink("my.htm", append=T) cat(sep="", "<", "IMG SRC=\"my.gif\"", ">") sink() graphsheet(format="GIF", file="my.gif") xyplot(Mileage~Weight, fuel.frame) dev.off()