\oddsidemargin  .5in
\evensidemargin .5in

\setkeys{Gin}{width=.25\textwidth}


This is an example of an {\tt Rmarkdown} file.  Run the
{\tt irisMarkdown.Rmd} file through {\tt knit} to create file
{\tt irisMarkdown.md} file, which despite its name, is actually a {\tt tex}
file.  The {\tt irisMarkdown.md} file can be included in a larger tex
document.  Or the {\tt irisMarkdown.md} file can be converted directly to a
{\tt pdf} file with the {\tt Hmisc::dvi} function.

Table \ref{irisBW5num} was generated by the
\verb:```{r construct, include=FALSE}:
chunk and included in this {\tt Rmd} file.

The file was run by
\begin{verbatim}
knitr::knit("irisMarkdown.Rmd")
latexSetOptions()
dvi(irisMarkdown.latex, width=8.5, height=11, nomargins=FALSE)
\end{verbatim}

```{r construct, include=FALSE}
library(microplot)
library(lattice)

iris.melt <- reshape2::melt(iris, id="Species")
irisBW <- bwplot( ~ value | Species * variable, data=iris.melt)

## twelve individual boxplots without axes
irisBW.update <-
update(irisBW,
       xlab=NULL,
       par.settings=list(
         layout.heights=layoutHeightsCollapse(),
         layout.widths=layoutWidthsCollapse(),
         axis.line=list(col="transparent")),
       layout=c(1,1)
       )


pdf("irisBW%03d.pdf", onefile=FALSE, height=.4, width=1.6)  ## inch ## BB = 0 0 216 28
irisBW.update
suppress <- dev.off()

graphnames <- paste0("irisBW", sprintf("%03i", 1:12), ".pdf")

graphicsnames <- t(matrix(as.includegraphics(graphnames, height="2em", raise="-1.3ex"),
                          nrow=3, ncol=4,
                          dimnames=dimnames(irisBW)))

## Each of the twelve Species*Measurement with its five number summary
iris2 <- array(iris.melt$value, ## $
               dim=c(50, 3, 4),
               dimnames=list(NULL,
                 levels(iris.melt$Species),
                 levels(iris.melt$variable)))
iris2.fivenum <- apply(iris2, 2:3, fivenum)
dimnames(iris2.fivenum)[[1]] <- c("min", "Q1", "med", "Q3", "max")

## Species and Measurement in separate columns
BW5num <-
rbind(
data.frame(t(iris2.fivenum[,1,]), "Box Plots"=graphicsnames[,1], check.names=FALSE),
data.frame(t(iris2.fivenum[,2,]), "Box Plots"=graphicsnames[,2], check.names=FALSE),
data.frame(t(iris2.fivenum[,3,]), "Box Plots"=graphicsnames[,3], check.names=FALSE))
BW5num$Measurement=levels(iris.melt$variable)
BW5num <- BW5num[, c(7,1:6)]

BW5num.latex <- latex(BW5num,
                      rowname=" ",
                      rowlabel="Species",
                      rgroup=levels(iris.melt$Species),
                      n.rgroup=c(4,4,4),
                      cgroup=c("", "Five Number Summary", ""),
                      n.cgroup=c(1, 5, 1),
                      caption="Five Number Summary and Box Plots for each Species and Measurement.",
                      label="irisBW5num")
BW5num.latex$style <- "graphicx"
## BW5num.latex  ## this line requires latex in the path
## the BW5num.latex line is not needed when the file is used in a \verb:\input: statement.

irisMarkdown.latex <-
  list(file="irisMarkdown.md",
       style=c("graphicx",
         paste0(system.file(), "/../../share/texmf/tex/latex/Sweave")))
class(irisMarkdown.latex) <- "latex"
```

```{r latexTable, results='asis', echo=FALSE}
cat(readLines("BW5num.tex"), sep="\n")
```

