]> git.donarmstrong.com Git - xtable.git/commitdiff
Added test.xalign.xdigits.xdisplay.R to evaluate feature request 5686
authorarnima <arnima@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Sun, 14 Sep 2014 22:59:08 +0000 (22:59 +0000)
committerarnima <arnima@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Sun, 14 Sep 2014 22:59:08 +0000 (22:59 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@48 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/tests/test.xalign.xdigits.xdisplay.R [new file with mode: 0644]

diff --git a/pkg/tests/test.xalign.xdigits.xdisplay.R b/pkg/tests/test.xalign.xdigits.xdisplay.R
new file mode 100644 (file)
index 0000000..32297e4
--- /dev/null
@@ -0,0 +1,49 @@
+### Test of feature request #5686
+### Automatically suggesting alignment/digits/display for an xtable
+### Arni Magnusson, 14 Sep 2014
+
+require(xtable)
+dat <- mtcars[1:3, 1:6]
+x <- xtable(dat)
+x
+
+## % latex table generated in R 3.1.1 by xtable 1.7-4 package
+## % Sun Sep 14 22:32:17 2014
+## \begin{table}[ht]
+## \centering
+## \begin{tabular}{rrrrrrr}
+##   \hline
+##  & mpg & cyl & disp & hp & drat & wt \\
+##   \hline
+## Mazda RX4 & 21.00 & 6.00 & 160.00 & 110.00 & 3.90 & 2.62 \\
+##   Mazda RX4 Wag & 21.00 & 6.00 & 160.00 & 110.00 & 3.90 & 2.88 \\
+##   Datsun 710 & 22.80 & 4.00 & 108.00 & 93.00 & 3.85 & 2.32 \\
+##    \hline
+## \end{tabular}
+## \end{table}
+
+### Hmm, inappropriate alignment and digits.
+### Now try suggestions from xalign, xdigits, and xdisplay:
+
+source("http://www.hafro.is/~arnima/r/xtable_5686.R")
+align(x) <- xalign(x)
+digits(x) <- xdigits(x)
+display(x) <- xdisplay(x)
+x
+
+## % latex table generated in R 3.1.1 by xtable 1.7-4 package
+## % Sun Sep 14 22:34:43 2014
+## \begin{table}[ht]
+## \centering
+## \begin{tabular}{lrrrrrr}
+##   \hline
+##  & mpg & cyl & disp & hp & drat & wt \\
+##   \hline
+## Mazda RX4 & 21.0 & 6 & 160 & 110 & 3.90 & 2.620 \\
+##   Mazda RX4 Wag & 21.0 & 6 & 160 & 110 & 3.90 & 2.875 \\
+##   Datsun 710 & 22.8 & 4 & 108 & 93 & 3.85 & 2.320 \\
+##    \hline
+## \end{tabular}
+## \end{table}
+
+### Excellent suggestions.