From 795ae3b2b096c3e812d84f7eab3c83cc9a68f0cd Mon Sep 17 00:00:00 2001 From: dscott Date: Thu, 10 Dec 2015 11:34:19 +0000 Subject: [PATCH] Completed addition of function print.xtableMatharray.R including test code in tests, and an example in the gallery. git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@75 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/NEWS | 4 ++- pkg/R/print.xtableMatharray.R | 2 +- pkg/R/xtable.R | 2 +- pkg/man/print.xtableMatharray.Rd | 39 ++++++++++++++++++++++---- pkg/man/xtable.Rd | 1 + pkg/tests/test.matharray.R | 47 +++++++++++++++----------------- 6 files changed, 62 insertions(+), 33 deletions(-) diff --git a/pkg/NEWS b/pkg/NEWS index bd83d92..a6025c4 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -1,5 +1,7 @@ 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. + 1.8-0 * autoformat, xalign, xdigits, xdisplay from Arni Magnusson, added along with help file. Feature request #5686. diff --git a/pkg/R/print.xtableMatharray.R b/pkg/R/print.xtableMatharray.R index 63515b8..5c83175 100644 --- a/pkg/R/print.xtableMatharray.R +++ b/pkg/R/print.xtableMatharray.R @@ -1,5 +1,5 @@ print.xtableMatharray <- function(x, - print.results = FALSE, + print.results = TRUE, format.args = getOption("xtable.format.args", NULL), scalebox = getOption("xtable.scalebox", NULL), comment = FALSE, diff --git a/pkg/R/xtable.R b/pkg/R/xtable.R index 76a4be9..e3c1e04 100644 --- a/pkg/R/xtable.R +++ b/pkg/R/xtable.R @@ -80,7 +80,7 @@ xtable.xtableMatharray <- function(x, caption = NULL, label = NULL, digits = digits, display = display, auto = auto, ...) class(xtbl) <- c("xtableMatharray","xtable","data.frame") - return(xtbl) + return(xtbl) } ### table objects (of 1 or 2 dimensions) by Guido Gay, 9 Feb 2007 diff --git a/pkg/man/print.xtableMatharray.Rd b/pkg/man/print.xtableMatharray.Rd index fc76f2e..e725f93 100644 --- a/pkg/man/print.xtableMatharray.Rd +++ b/pkg/man/print.xtableMatharray.Rd @@ -7,7 +7,7 @@ } \usage{ \method{print}{xtableMatharray}(x, - print.results = FALSE, + print.results = TRUE, format.args = getOption("xtable.format.args", NULL), scalebox = getOption("xtable.scalebox", NULL), comment = FALSE, @@ -19,7 +19,7 @@ \item{print.results}{If \code{TRUE}, the generated table is printed to standard output. Set this to \code{FALSE} if you will just be using the character vector that is returned invisibly. - Default value is \code{FALSE}.} + Default value is \code{TRUE}.} \item{format.args}{List of arguments for the \code{formatC} function. For example, standard German number separators can be specified as \code{format.args=list(big.mark = "'", decimal.mark = ",")}. The @@ -37,7 +37,15 @@ \item{...}{Additional arguments. (Currently ignored.) } } \details{ - Here are some details. + This command prints an array of numbers which may be included in a + mathematical expression in a LaTeX document created using \pkg{Sweave} + or \pkg{knitr}. Internally it calls \code{print.data.frame} but with + special values for the arguments, namely that the tabular environment + is \code{array}, row names and column names are not included, and there + are no horizontal lines. Note that the default values for the arguments + \code{comment} and \code{timestamp} are different to the default values + for \code{print.xtable}, the justification being that comments would + make the resulting LaTeX harder to read. } \value{ A character vector containing the LaTeX code for incorporating an @@ -55,13 +63,34 @@ V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05, 3.010497e-05, 3.320683e-04, -5.284854e-05, 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3) -V +### Simple test of print.xtableMatharray +print.xtableMatharray(xtable(V, display = rep("E", 4))) + class(V) <- c("xtableMatharray") class(V) +### Test without any additional arguments mth <- xtable(V) str(mth) -mth +print(mth) + +### Test with arguments to xtable +mth <- xtable(V, display = rep("E", 4)) +str(mth) +print(mth) + +mth <- xtable(V, digits = 6) +str(mth) +print(mth) + +### Test with additional print.xtableMatharray arguments +mth <- xtable(V, digits = 6) +str(mth) +print(mth, format.args = list(decimal.mark = ",")) +print(mth, scalebox = 0.5) +print(mth, comment = TRUE) +print(mth, timestamp = "2000-01-01") +print(mth, comment = TRUE, timestamp = "2000-01-01") } \keyword{print} diff --git a/pkg/man/xtable.Rd b/pkg/man/xtable.Rd index cb33e88..33bb8cd 100644 --- a/pkg/man/xtable.Rd +++ b/pkg/man/xtable.Rd @@ -7,6 +7,7 @@ \alias{xtable.glm} \alias{xtable.lm} \alias{xtable.matrix} +\alias{xtable.xtableMatharray} \alias{xtable.prcomp} \alias{xtable.coxph} \alias{xtable.summary.aov} diff --git a/pkg/tests/test.matharray.R b/pkg/tests/test.matharray.R index fed6f85..3f51aa2 100644 --- a/pkg/tests/test.matharray.R +++ b/pkg/tests/test.matharray.R @@ -2,39 +2,36 @@ require(xtable) V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05, 3.010497e-05, 3.320683e-04, -5.284854e-05, 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3) -V +### Simple test of print.xtableMatharray +print.xtableMatharray(xtable(V, display = rep("E", 4))) + class(V) <- c("xtableMatharray") class(V) +### Test without any additional arguments mth <- xtable(V) str(mth) -mth - -tbl <- xtable(V, display = rep("E", 4)) -str(tbl) -tbl +print(mth) -V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05, - 3.010497e-05, 3.320683e-04, -5.284854e-05, - 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3) -V +### Test with arguments to xtable mth <- xtable(V, display = rep("E", 4)) -class(mth) -mth -class(mth) <- c("xtableMatharray") -mth +str(mth) print(mth) -print.xtableMatharray(xtable(V, display = rep("E", 4))) -class(mth) <- c("xtableMatharray") -mth -V <- matrix(c(1.140380e-03, 3.010497e-05, 7.334879e-05, - 3.010497e-05, 3.320683e-04, -5.284854e-05, - 7.334879e-05, -5.284854e-05, 3.520928e-04), nrow = 3) -V +mth <- xtable(V, digits = 6) +str(mth) +print(mth) + +### Test with additional print.xtableMatharray arguments +mth <- xtable(V, digits = 6) +str(mth) +print(mth, format.args = list(decimal.mark = ",")) +print(mth, scalebox = 0.5) +print(mth, comment = TRUE) +print(mth, timestamp = "2000-01-01") +print(mth, comment = TRUE, timestamp = "2000-01-01") + + + -print.xtableMatharray(xtable(V), - format.args = list(display = rep("E", 4))) -print.xtableMatharray(xtable(V), - format.args = list(digits = 6)) -- 2.39.5