]> git.donarmstrong.com Git - xtable.git/commitdiff
Added sanitization example to the gallery
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Mon, 14 Dec 2015 02:46:39 +0000 (02:46 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Mon, 14 Dec 2015 02:46:39 +0000 (02:46 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@76 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/NEWS
pkg/vignettes/xtableGallery.Rnw

index a6025c4ae1db89cbb3d9d20b4f3fb45950256506..2def7fbdc7ad94f1acb724b488d39e64724f70b5 100644 (file)
--- a/pkg/NEWS
+++ b/pkg/NEWS
@@ -1,6 +1,8 @@
 1.8-1 (NOT YET SUBMITTED TO CRAN)
   * added function print.xtableMatharray to enable easy creation of
     LaTeX code to enable an array to be included in a document.
+  * added example to the gallery using sanitizing headings and row
+    names to produce large bold headings and italic row names.
   
 1.8-0
   * autoformat, xalign, xdigits, xdisplay from Arni Magnusson, added
index 4aa6d43f9fca060f2db4338efd7b767189e7110a..6b7d47b3327244659e9d49a14a5c1a181019a941 100644 (file)
@@ -7,7 +7,6 @@
 %**************************************************************************\r
 \documentclass{article}\r
 \usepackage[a4paper,height=24cm]{geometry} % geometry first\r
-\usepackage{listings}\r
 \usepackage{array}\r
 \usepackage{booktabs}\r
 \usepackage{longtable}\r
 \newcommand\code[1]{\texttt{#1}}\r
 \newcommand\pkg[1]{\textbf{#1}}\r
 \setcounter{tocdepth}{2}\r
-\r
-\lstset{language=R,basicstyle=\ttfamily,\r
-        keywordstyle=\ttfamily,\r
-        emphstyle=\itshape,\r
-        escapeinside = ||,\r
-        lineskip=0pt}\r
-\r
 \begin{document}\r
 \r
 \title{The \pkg{xtable} Gallery}\r
@@ -52,6 +44,7 @@ The first step is to load the package and set an option for this document.
 <<results='asis'>>=\r
 library(xtable)\r
 options(xtable.floating = FALSE)\r
+options(xtable.timestamp = "")\r
 @\r
 \r
 \section{Gallery}\r
@@ -129,36 +122,6 @@ temp.table <- xtable(temp.ts, digits = 0)
 temp.table\r
 @\r
 \r
-\subsection{Mathematical arrays}\r
-\label{sec:mathematical-arrays}\r
-\r
-Mathematical arrays (as compared to data arrays) can be printed\r
-correctly by declaring the class as \code{xtableMatharray}.\r
-<<matharraydata>>=\r
-V <- matrix(c(1.140380e-03,  3.010497e-05,  7.334879e-05,\r
-              3.010497e-05,  3.320683e-04, -5.284854e-05,\r
-              7.334879e-05, -5.284854e-05,  3.520928e-04), nrow = 3)\r
-V\r
-class(V) <- c("xtableMatharray")\r
-class(V)\r
-xtbl <- print(xtable(V, display = rep("E", 4)))\r
-@ %def\r
-\r
-Then \code{xtbl} can be used in an expression such as\r
-$V=\left[\Sexpr{xtbl}\right]$, produced by\r
-\begin{lstlisting}\r
-V=\left[\Sexp||r{xtbl}\right]. \r
-\end{lstlisting}\r
-\r
-\r
-An alternative display can be created using the \texttt{digits}\r
-argument. If \code{xtbl} is defined instead according to\r
-\r
-<<altmatharray, results = 'hide'>>=\r
-xtbl <- print(xtable(V, digits = 6))\r
-@ %def \r
-then we get\\\r
-$V=\left[\Sexpr{paste(print(xtable(V, digits = 6)))}\right].$ \r
 \newpage\r
 \r
 <<include=FALSE>>=\r
@@ -240,6 +203,7 @@ xtable(insane)
 \p\r
 Sometimes you might want to have your own sanitization function.\r
 \r
+\r
 <<results='asis'>>=\r
 wanttex <- xtable(data.frame(Column =\r
                              paste("Value_is $10^{-",1:3,"}$", sep = "")))\r
@@ -247,6 +211,27 @@ print(wanttex, sanitize.text.function =
       function(str) gsub("_", "\\_", str, fixed = TRUE))\r
 @\r
 \r
+\p\r
+Sanitization can be useful in formatting column headings and row names:\r
+\r
+<<sanitize3>>=\r
+dat <- mtcars[1:3, 1:6]\r
+large <- function(x){\r
+  paste0('{\\Large{\\bfseries ', x, '}}')\r
+}\r
+italic <- function(x){\r
+  paste0('{\\emph{ ', x, '}}')\r
+}\r
+@ %def\r
+\r
+<<sanitize4, results = 'asis'>>=\r
+print(xtable(dat),\r
+      sanitize.rownames.function = italic,\r
+      sanitize.colnames.function = large,\r
+      booktabs = TRUE)\r
+@ %def\r
+\r
+\r
 \r
 \newpage\r
 \r
@@ -276,8 +261,6 @@ money <- matrix(c("$1,000","$900","$100"), ncol = 3,
 print(xtable(money), sanitize.rownames.function = function(x) {x})\r
 @\r
 \r
-\r
-\r
 \section{Format examples}\r
 \subsection{Adding a centering environment}\r
 <<results='asis'>>=\r
@@ -332,27 +315,6 @@ digits(tli.table) <- matrix(0:4, nrow = 10, ncol = ncol(tli)+1)
 tli.table\r
 @\r
 \r
-\subsection{Minus signs}\r
-\label{sec:minus-signs}\r
-\r
-The standard print functions do not render minus signs properly. They\r
-are actually hyphens (-) rather than minus signs ($-$). True minus\r
-signs can be obtained using the \code{math.style.negative} argument.\r
-\r
-\p\r
-Here is the \LaTeX{} which is produced:\r
-\r
-<<>>=\r
-pr1 <- prcomp(USArrests)\r
-print(xtable(pr1), math.style.negative = TRUE)\r
-@ \r
-\r
-And here is the resulting table.\r
-<<results='asis'>>=\r
-print(xtable(pr1), math.style.negative = TRUE)\r
-@\r
-\r
-\r
 \newpage\r
 \r
 \subsection{Suppress row/column names}\r