From 7c1e8225195d8a169c82a8e90b132399d4cb770e Mon Sep 17 00:00:00 2001 From: roosen Date: Mon, 30 Jan 2012 15:48:54 +0000 Subject: [PATCH] Added "rotate.rownames" and "rotate.colnames" arguments as suggested by Marcus Loecher in email dated Nov, 2009. git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@24 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/NEWS | 2 ++ pkg/R/print.xtable.R | 35 +++++++++++++++++++++++++--------- pkg/inst/doc/xtableGallery.snw | 8 ++++++++ pkg/man/print.xtable.Rd | 7 ++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/pkg/NEWS b/pkg/NEWS index 0498e42..78eefef 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -7,6 +7,8 @@ pass additional arguments such as "big.marks" to "formatC()". * Added "short.caption" argument to "print" to let the user specify a Latex short caption used when creating a list of tables. + * Added "rotate.colnames" and "rotate.rownames" arguments to + "print.xtable". * Added an "is.null()" check on the "table.placement" argument. * Put in some changes from John Leonard regarding the placement of newlines when "longtable" and "add.to.row" are used together. diff --git a/pkg/R/print.xtable.R b/pkg/R/print.xtable.R index 9b73f31..2c1c5dc 100644 --- a/pkg/R/print.xtable.R +++ b/pkg/R/print.xtable.R @@ -47,6 +47,8 @@ print.xtable <- function( print.results=TRUE, format.args=NULL, short.caption=NULL, + rotate.rownames=FALSE, + rotate.colnames=FALSE, ...) { # Claudio Agostinelli dated 2006-07-28 hline.after # By default it print an \hline before and after the columns names independently they are printed or not and at the end of the table @@ -324,22 +326,37 @@ print.xtable <- function( # Claudio Agostinelli dated 2006-07-28 include.colnames, include.rownames if (include.colnames) { result <- result + BROW + BTH - if (include.rownames) result <- result + STH - if (is.null(sanitize.colnames.function)) { # David G. Whiting in e-mail 2007-10-09 - result <- result + paste(sanitize(names(x)),collapse=STH) - } else { - result <- result + paste(sanitize.colnames.function(names(x)), collapse=STH) # David G. Whiting in e-mail 2007-10-09 - } + if (include.rownames) { + result <- result + STH + } + # David G. Whiting in e-mail 2007-10-09 + if (is.null(sanitize.colnames.function)) { + CNAMES <- sanitize(names(x)) + } else { + CNAMES <- sanitize.colnames.function(names(x)) + } + if (rotate.colnames) { + #added by Markus Loecher, 2009-11-16 + CNAMES <- paste("\\begin{sideways}", CNAMES, "\\end{sideways}") + } + result <- result + paste(CNAMES, collapse=STH) + result <- result + ETH + EROW } cols <- matrix("",nrow=nrow(x),ncol=ncol(x)+pos) if (include.rownames) { - if (is.null(sanitize.rownames.function)) { # David G. Whiting in e-mail 2007-10-09 - cols[,1] <- sanitize(row.names(x)) + # David G. Whiting in e-mail 2007-10-09 + if (is.null(sanitize.rownames.function)) { + RNAMES <- sanitize(row.names(x)) } else { - cols[,1] <- sanitize.rownames.function(row.names(x)) # David G. Whiting in e-mail 2007-10-09 + RNAMES <- sanitize.rownames.function(row.names(x)) } + if (rotate.rownames) { + #added by Markus Loecher, 2009-11-16 + RNAMES <- paste("\\begin{sideways}", RNAMES, "\\end{sideways}") + } + cols[,1] <- RNAMES } ## Begin vectorizing the formatting code by Ian Fellows [ian@fellstat.com] diff --git a/pkg/inst/doc/xtableGallery.snw b/pkg/inst/doc/xtableGallery.snw index 2298c93..79d1626 100644 --- a/pkg/inst/doc/xtableGallery.snw +++ b/pkg/inst/doc/xtableGallery.snw @@ -388,6 +388,14 @@ print(tli.table,include.colnames=FALSE,floating=FALSE,hline.after=c(0,nrow(tli.t print((tli.table),include.colnames=FALSE,include.rownames=FALSE,floating=FALSE) @ +\subsection{Rotate row and column names} +The {\tt rotate.rownames } and {\tt rotate.colnames} arguments can be +used to rotate the row and/or column names. + +<>= +print((tli.table),rotate.rownames=TRUE,rotate.colnames=TRUE) +@ + \subsection{Horizontal lines} <>= print(xtable(anova(glm.D93)),hline.after=c(1),floating=FALSE) diff --git a/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd index fdf2df9..877fc04 100644 --- a/pkg/man/print.xtable.Rd +++ b/pkg/man/print.xtable.Rd @@ -13,7 +13,10 @@ html.table.attributes="border=1", print.results=TRUE, format.args=NULL, - short.caption=NULL, ...)} + short.caption=NULL, + rotate.rownames = FALSE, + rotate.colnames = FALSE, + ...)} \arguments{ \item{x}{An object of class \code{"xtable"}.} \item{type}{Type of table to produce. Possible values for \code{type} are \code{"latex"} or \code{"html"}. @@ -49,6 +52,8 @@ \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.} \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 = ","))}.} \item{short.caption}{A "short caption" can be specified that gets used as the table descriptor when LaTeX generates a "List of Tables".} + \item{rotate.rownames}{If \code{TRUE}, the row names are displayed vertically in LaTeX.} + \item{rotate.colnames}{If \code{TRUE}, the column names are displayed vertically in LaTeX.} \item{...}{Additional arguments. (Currently ignored.)} } \details{ -- 2.39.5