Description Usage Arguments Details Value Author(s) See Also Examples
hwriteOutput
is a wrapper function for hwrite
which
formats output from R captured by capture.output
so it
appears correctly when hwrite
is called.
hwriteScript
is a very similar wrapper function for hwrite
which formats an R session captured by script
so it appears
correctly when hwrite
is called. hwriteScript
also
optionally trims lines added at the beginning and end of the session by
script
.
1 2 3 4 |
output |
Text. Output produced by R, captured by
|
page |
An optional connection. A character string naming the
file to write to or a page object returned by |
fontSize |
Character string. The font size in points in which the
output will be displayed. A positive number followed by the characters
|
scriptFile |
File. Contains text from an R session captured by
|
trim |
A logical. If |
... |
Optional arguments. See Details section of
|
link |
A character vector containing the URLs the HTML element
will point to. This argument is the equivalent of the attribute
|
name |
A character string naming the HTML element for further
reference. This is the equivalent of the attribute |
br |
A logical specifying if a breakline (carriage return) should
be appended at the end of |
div |
A logical. If |
The output obtained from R using capture.output
is
modified by these functions so that it will appear verbatim in the
resulting HTML file, as preformatted text.
The output is first modified by adding characters "\n"
to the
end of each output line. Then preformatting tags are added to surround
the output. The opening preformatting tag includes a style definition
which sets the font size to that specified by fontSize
.
In addition hwriteScript
can trim off the first line and the
last two lines of the text returned by a call to script
. The
first and last lines record the start and end times of the call to
script
. The second last line typically consists of the text
> q()
comprised of the R prompt and the call to q()
which terminates the recording of the session by script
.
A character vector containing the output HTML code.
David Scott d.scott@auckland.ac.nz
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 | ### Example results written to standard output stream
### Annette Dobson (1990) "An Introduction to Generalized Linear Models".
### Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
plants <- data.frame(weight = weight, group = group)
strOutput <- capture.output(str(plants))
lm.D9 <- lm(weight ~ group, data = plants)
anovaOutput <- capture.output(anova(lm.D9))
hwrite("Analysis of Weight Data", heading = 1,
center = FALSE, br = TRUE)
hwriteOutput(strOutput, fontSize = "8pt")
hwriteOutput(anovaOutput)
### Same example but written to a file
tmpDir <- tempdir()
fileName <- file.path(tmpDir, 'hwriterPlus.html')
p <- newPage(fileName)
hwrite("Analysis of Weight Data", p, heading = 1,
center = FALSE, br = TRUE)
hwriteOutput(strOutput, p, fontSize = "8pt")
hwriteOutput(anovaOutput, p)
closePage(p)
### Open a web browser and examine the resulting file
if (interactive()) try(browseURL(fileName))
### Record of session captured by script written to temporary file
## Not run: tmpDir <- tempdir()
tmpFile <- file.path(tmpDir, 'script.txt')
script(tmpFile)
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
plants <- data.frame(weight = weight, group = group)
lm.D9 <- lm(weight ~ group, data = plants)
q()
sessionOut <- readLines(tmpFile)
sessionOut
hwriteScript(tmpFile, br = TRUE)
hwriteScript(tmpFile, trim = FALSE, fontSize = "8pt", br = TRUE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.