Description Usage Arguments Value Author(s) See Also Examples
Prints an object as a HTML unordered or ordered list.
Using the on
functions one can control the layout and the contents
of the list in full.
1 2 |
type |
If |
x |
Object whose values are to be printed. |
... |
Named attribute list for the first list tag. |
onUl |
Function to be called when a |
onOl |
Function to be called when a |
onLi |
Function to be called when a |
onCell |
Function to be called when a subitem in |
sep |
A character string to separate the terms in each list item.
Default value is |
collapse |
A character string to separate the results. Default value
is |
path |
Used internally only. |
Returns nothing.
Henrik Bengtsson (http://www.braju.com/R/)
*printUl()
,
*printOl()
,
*printDl()
, and
*printTable()
.
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | require(R.lang) # load class System
# Writes the HTML code directly to the standard output and
# buffered to file. Note that the file will not be filled
# until the buffer stream flushed.
stdout <- PrintStream(ConnectionOutputStream(stdout()))
file <- File$createTempFile(suffix=".html")
fout <- FileOutputStream(file)
out2 <- BufferedOutputStream(fout)
mout <- MultiOutputStream(stdout, out2)
out <- HtmlPrintStream(mout)
l <- list(a=1:10, b=2, c=list(ca=-4:4, cb="Hello world!"), d=4);
# ----------------------------------------------------------------------
# Start writing the HTML document
# ----------------------------------------------------------------------
# Write document type
writeDocType(out)
# Start by writing a time stamp comment
printTimestamp(out)
# ----------------------------------------------------------------------
# Write the header
# ----------------------------------------------------------------------
pushTag(out, "html")
pushTag(out, "head")
printTag(out, "title", "Example of HtmlPrintStream")
popTag(out)
printTag(out, "meta", content="text/html; charset=iso-8859-1",
"http-equiv"="Content-Type", endTag=FALSE)
printTag(out, "meta", name="Author",
content="[R] and R.classes, http://www.r-project.org", endTag=FALSE)
pushTag(out, "body")
printComment(out, "B O D Y")
# ----------------------------------------------------------------------
# Write simple unordered list
# ----------------------------------------------------------------------
printTag(out, "h1", "Easiest way to print an unordered list")
printUl(out, l)
# ----------------------------------------------------------------------
# Write simple ordered list
# ----------------------------------------------------------------------
printTag(out, "h1", "Easiest way to print an ordered list")
printOl(out, l)
# ----------------------------------------------------------------------
# Write advanced unordered list
# ----------------------------------------------------------------------
printTag(out, "h1", "Advanced way to print a unordered list")
onCell <- function(path, index, hout, value, ...) {
depth <- length(path)
color <- colors()[16*index+5*depth+5]
if (is.numeric(value) && value < 0)
color <- "red";
pushTag(hout, "font", color=color, newline=FALSE);
print(hout, value);
popTag(hout, indent=FALSE);
}
printUl(out, l, onCell=onCell)
# ----------------------------------------------------------------------
# Finish writing the HTML document
# ----------------------------------------------------------------------
# Pop all tags left on the tag stack
popTags(out)
# Finish by writing a time stamp comment
printTimestamp(out)
# Don't forget to close the output stream(s)!
close(out)
if (interactive()) {
cat("Tries to open the file in the default browser...\n")
System$openBrowser(file)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.