Description Usage Arguments Fields and Methods Author(s) Examples
Package: R.io
Class Reporter
Object
~~|
~~+--
Reporter
Directly known subclasses:
HtmlReporter, LaTeXReporter, MultiReporter, TextReporter
public abstract static class Reporter
extends Object
This abstract class is the superclass of all Reporter classes.
1 |
out |
|
isCreator |
If |
Methods:
beginBold | - | |
beginComment | - | |
beginDebug | - | |
beginEmphased | - | |
beginEquation | - | |
beginFigure | - | |
beginItalic | - | |
beginParagraph | - | |
beginVerbatim | - | |
close | Closes the reporter. | |
endBold | - | |
endComment | - | |
endDebug | - | |
endEmphased | - | |
endEquation | - | |
endFigure | - | |
endItalic | - | |
endParagraph | - | |
endVerbatim | - | |
finalize | Finalizes the reporter by first closing it. | |
getExtension | - | |
getFigureFilename | - | |
getFigureNameFormat | - | |
getVerbatim | - | |
getVerbatimOld | - | |
include | - | |
isCreator | Checks if reporter is a creator or not. | |
open | Opens the reporter. | |
popRedirect | - | |
prepareTable | - | |
pushRedirect | - | |
setAuthor | Sets the author of the document. | |
setCreator | Sets this reporter to be a creator of figures etc. | |
setDate | Sets the date of the document. | |
setFigureNameFormat | Sets the sprintf-style format of figure names. | |
setFigurePath | Sets the path where figures are written. | |
setIncludePath | Sets the path where includes are written. | |
setTitle | Sets the title of the document. | |
write | Writes objects to document. | |
writeAndEvaluateCode | Writes and then evaluates the code. | |
writeBold | Writes a sentence in bold face font. | |
writeComment | Writes a comment not visible in the final document. | |
writeDebug | Writes debug information. | |
writeEmphased | Writes a sentence in an emphasized font. | |
writeEquation | Writes an equation. | |
writeError | - | |
writeFigure | Writes a figure by saving the current plot. | |
writeHorizontalRuler | Adds a horizontal ruler to the document. | |
writeImage | - | |
writeItalic | Writes a sentence in an italic font. | |
writeList | Writes a list. | |
writeNewLine | Adds a new line/carrage return to the document. | |
writeParagraph | Writes a paragraph. | |
writeSection | Begins a section. | |
writeSubsection | Begins a subsection. | |
writeSubsubsection | Begins a subsubsection. | |
writeTable | Writes a table. | |
writeText | Writes a text. | |
writeTitle | Writes the title. | |
writeVerbatim | Writes an object in verbatim. | |
writeWarning | - | |
Methods inherited from Object:
$, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clone, detach, equals, extend, finalize, gc, getEnvironment, getFields, getInstanciationTime, getStaticInstance, hasField, hashCode, ll, load, objectSize, print, save
Henrik Bengtsson (http://www.braju.com/R/)
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | library(R.basic) # points3d
library(R.lang) # System$out
library(R.graphics) # Device$...
fig <- 1
fout <- FileOutputStream("ReporterExample.html")
htmlReport <- HtmlReporter(fout)
stdout <- PrintStream(ConnectionOutputStream(stdout()))
textReport <- TextReporter(stdout, isCreator=FALSE)
report <- MultiReporter(textReport, htmlReport)
#latexReport <- LaTeXReporter(FileOutputStream("ReporterExample.tex"))
#report <- MultiReporter(textReport, htmlReport, latexReport)
setTitle(report, "Reporter Example")
setAuthor(report, author="http://www.braju.com/R/")
setDate(report)
open(report)
writeSection(report, "Some simple list examples")
l <- list(numbers=1:10, letters=letters);
writeList(report, l, type="123abc")
writeList(report, l, type="itemized")
writeSection(report, "Mathematical equation")
writeParagraph(report, "The Reporter has special functions for writing mathematical equations, which should be written using LaTeX style. The HTMLReporter class will try to translate some of the LaTeX symbols into special HTML symbol (which some browser might not support). If the symbol/command is unknown it is written in verbatim.");
writeEquation(report, c("\\alpha, \\beta, \\gamma, \\delta, \\epsilon, \\varepsilon, \\zeta, \\eta, \\theta, \\iota, \\kappa, \\lambda, \\mu, \\nu, \\xi, \\pi, \\rho, \\sigma, \\tau, \\upsilon, \\phi, \\chi, \\psi, \\omega"))
writeEquation(report, c("\\Gamma, \\Delta, \\Theta, \\Lambda, \\Xi, \\Pi, \\Sigma, \\Upsilon, \\Phi, \\Omega"))
writeEquation(report, c("A \\leftarrow B \\leftrightarrow C \\rightarrow D \\uparrow E \\downarrow E"))
writeEquation(report, c("A \\leq B \\geq C \\neq D \\approx E"))
writeSection(report, "From the examples of persp() and contour()")
writeSubsection(report, "The Obligatory Mathematical surface. Rotated sinc function.")
writeEquation(report, "f(x,y) = 10 \\cdot \\frac{sin(\\sqrt(x^2+y^2))}{\\sqrt(x^2+y^2)}")
x <- seq(-10, 10, length=50)
y <- x
f <- function(x,y) {
r <- sqrt(x^2+y^2)
10 * sin(r)/r
}
z <- outer(x, y, f)
z[is.na(z)] <- 1
if (create <- !Device$isOpen(fig <- fig + 1)) {
Device$set(fig);
par(bg="white")
persp(x, y, z, theta=30, phi=30, expand=0.5, col="lightblue",
xlab="X", ylab="Y", zlab="Z")
}
writeFigure(report, caption="persp()", create=create)
if (create <- !Device$isOpen(fig <- fig + 1)) {
Device$set(fig);
par(bg="white")
persp(x, y, z, theta=30, phi=30, expand=0.5, col="lightblue",
ltheta=120, shade=0.75, ticktype="detailed",
xlab="X", ylab="Y", zlab="Z")
}
writeFigure(report, caption="persp()", create=create)
writeSection(report, "The vulcano Mt Eden")
data(volcano)
z <- volcano # Exaggerate the relief
x <- 10 * (1:nrow(z)) # 10 meter spacing (S to N)
y <- 10 * (1:ncol(z)) # 10 meter spacing (E to W)
maxZ <- max(z)
maxCoord <- which(volcano >= maxZ, arr.ind=TRUE)
maxX <- x[maxCoord[1]]
maxY <- x[maxCoord[2]]
writeParagraph(report, "The Maori name of Mt Eden is Maungawhau, which means 'Hill of the Whau Tree'. Mt Eden is ", maxZ, " meters high (see red dot on maps below) and is one of Auckland's most famous landmarks.");
if (create <- !Device$isOpen(fig <- fig + 1)) {
Device$set(fig);
par(bg="white")
pmat <- persp(x, y, z, theta=120, phi=15, expand=2, scale=FALSE, axes=FALSE)
points3d(maxX, maxY, maxZ, pch=20, col="red", cex=1.3, persp.matrix=pmat)
}
writeFigure(report, caption="vulcano", create=create)
zmin <- min(z) - 20
z <- rbind(zmin, cbind(zmin, z, zmin), zmin)
x <- c(min(x) - 1e-10, x, max(x) + 1e-10)
y <- c(min(y) - 1e-10, y, max(y) + 1e-10)
fill <- matrix("green3", nr=nrow(z)-1, nc=ncol(z)-1)
fill[,1] <- "gray"
fill[,ncol(fill)] <- "gray"
fill[1,] <- "gray"
fill[nrow(fill),] <- "gray"
if (create <- !Device$isOpen(fig <- fig + 1)) {
Device$set(fig)
layout(matrix(1:2, ncol=2))
opar <- par(mar=c(0,1,1,1)+0.1, oma=c(0,0,3,0), pty = "s", bg = "transparent")
pmat <- persp(x, y, z, theta=135, phi=30, col=fill, expand=2, scale=FALSE,
ltheta=-120, lphi=15, shade=0.65, border=NA, axes=FALSE)
points3d(maxX, maxY, maxZ, pch=20, col="red", cex=1.3, persp.matrix=pmat)
rx <- range(xc <- 10*1:nrow(volcano))
ry <- range(yc <- 10*1:ncol(volcano))
ry <- ry + c(-1,1) * (diff(rx) - diff(ry))/2
tcol <- terrain.colors(100)
tcol[100] <- "red"
image(xc, yc, volcano, col=tcol, xlab="", ylab=NULL, axes=FALSE)
# plot(x=0, y=0, type="n", xlim=rx, ylim=ry, xlab="", ylab="")
u <- par("usr")
# rect(u[1], u[3], u[2], u[4], col=tcol[8], border="red")
tcol <- terrain.colors(12)
contour(xc, yc, volcano, col=tcol[2], lty="solid", add=TRUE,
vfont=c("sans serif", "plain"))
abline(h=200*0:4, v=200*0:4, col="lightgray", lty=2, lwd=0.1)
title(main="Maungawhau\nOne of 50 Volcanoes in the Auckland Region.", font.main=2, outer=TRUE)
par(opar)
}
writeFigure(report, caption="Left: Perspective map of the vulcano. Right: Contour map of the vulcano.", create=create)
writeSubsection(report, "The height map of the volcano")
x <- seq(1,ncol(volcano),by=2)
y <- seq(2,nrow(volcano),by=2)
z <- volcano[y,x]
rownames(z) <- 10*y
colnames(z) <- 10*x
z <- t(z)
tcol <- terrain.colors(100)
tcol <- substring(tcol, 1, 7) # From R v2.5.0
zbin <- ceiling((length(tcol)-1)*(z-min(z))/(max(z)-min(z))+0.00001)
col <- tcol[zbin]
tdStyle = paste("background: ", col, ";", sep="")
tdStyle[which.max(z)] <- paste("background: red;")
writeTable(report, z, cellspacing=1, cellpadding=0, style="text-align: right; font-size: xx-small;", tdStyle=tdStyle, caption="The height map of the volcano in meters.");
close(report)
System$openBrowser(fout$file)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.