From: dscott Date: Fri, 29 Jan 2016 01:59:13 +0000 (+0000) Subject: Completed package improvements notably xtableList and xtableFtable functions X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=8b830e4c1fd3c4c144982042d596cad090b25451;p=xtable.git Completed package improvements notably xtableList and xtableFtable functions and print methods git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@105 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE index 9daba6a..c912d90 100644 --- a/pkg/NAMESPACE +++ b/pkg/NAMESPACE @@ -10,8 +10,7 @@ export("caption<-", "caption", "label", "label<-", "xtableFtable", "print.xtableFtable", "toLatex.xtable", "autoformat", "xalign", "xdigits", "xdisplay", - "sanitize", "sanitize.numbers", "sanitize.final", "as.is", "as.math", - "format.ftable") + "sanitize", "sanitize.numbers", "sanitize.final", "as.is", "as.math") S3method("print", "xtable") S3method("print", "xtableMatharray") @@ -30,8 +29,6 @@ S3method("digits<-", "xtable") S3method("display<-", "xtable") S3method("display", "xtable") -S3method("format", "ftable") - S3method("xtable", "data.frame") S3method("xtable", "matrix") S3method("xtable", "table") diff --git a/pkg/NEWS b/pkg/NEWS index 057abe0..9c2291e 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -32,7 +32,7 @@ xtableList and print.xtableList; and 'The Other Packages Gallery' to illustrate methods for classes of objects from other packages. -1.8-0 +1.8-0 (2015-11-02) * autoformat, xalign, xdigits, xdisplay from Arni Magnusson, added along with help file. Feature request #5686. * New argument 'auto' in xtable(), to call xalign, xdigits, and diff --git a/pkg/R/xtableFtable.R b/pkg/R/xtableFtable.R index dafb6f0..72964d8 100644 --- a/pkg/R/xtableFtable.R +++ b/pkg/R/xtableFtable.R @@ -97,7 +97,7 @@ print.xtableFtable <- function(x, timestamp = getOption("xtable.timestamp", date()), ...) { if (type == "latex"){ - + ## extract the information in the attributes caption <- attr(x, "ftableCaption") label <- attr(x, "ftableLabel") align <- attr(x, "ftableAlign") @@ -110,15 +110,14 @@ print.xtableFtable <- function(x, nCharCols <- attr(x, "nChars")[2] nRowVars <- length(attr(x, "row.vars")) nColVars <- length(attr(x, "col.vars")) - fmtFtbl <- format.ftable(x, quote = quote, digits = digits, - method = method, lsep = lsep) + + ## change class so format method will find format.ftable + ## even though format.ftable is not exported from 'stats' + class(x) <- "ftable" + fmtFtbl <- format(x, quote = quote, digits = digits, + method = method, lsep = lsep) attr(fmtFtbl, "caption") <- caption attr(fmtFtbl, "label") <- label - ## if method is "compact", rotate both if either requested - ## if (method == "compact"){ - ## if (rotate.rownames) rotate.colnames <- TRUE - ## if (rotate.colnames) rotate.rownames <- TRUE - ## } ## sanitization is possible for row names and/or column names ## row names @@ -187,3 +186,12 @@ print.xtableFtable <- function(x, } } +## format.xtableFtable <- function(x, quote = TRUE, digits = getOption("digits"), +## method = c("non.compact", "row.compact", +## "col.compact", "compact"), +## lsep = " | ", ...){ +## class(x) <- "ftable" + +## format(x, quote = quote, digits = digits, +## method = method, lsep = lsep, ...) +## } diff --git a/pkg/man/xtableFtable.Rd b/pkg/man/xtableFtable.Rd index 5d6b2dc..2e743b1 100644 --- a/pkg/man/xtableFtable.Rd +++ b/pkg/man/xtableFtable.Rd @@ -274,9 +274,12 @@ xtableFtable(x, caption = NULL, label = NULL, \code{print.xtableFtable} uses the attributes attached to an object of class \code{c("xtableFtable", "ftable")} to create a suitable - character matrix object for subsequent printing via a call to - \code{stats:::format.ftable}. This matrix object is then printed via - a call to \code{print.xtable}. + character matrix object for subsequent printing. Formatting is + carried out by changing the class of the \code{c("xtableFtable", + "ftable")} to \code{"ftable"} then using the generic \code{format} + to invoke \code{format.ftable}, from the \pkg{stats} package. The + matrix object produced is then printed via a call to + \code{print.xtable}. Note that at present there is no code for \code{type = "html"}. } diff --git a/pkg/vignettes/xtableGallery.Rnw b/pkg/vignettes/xtableGallery.Rnw index bb41fab..c618d49 100644 --- a/pkg/vignettes/xtableGallery.Rnw +++ b/pkg/vignettes/xtableGallery.Rnw @@ -263,6 +263,7 @@ useful for formatting tables in a sensible way. Consider the output produced by the default formatting. <>= +data(mtcars) dat <- mtcars[1:3, 1:6] x <- xtable(dat) x