From 198cc2021276e9a13f1676818996092f18d3f6db Mon Sep 17 00:00:00 2001 From: dscott Date: Tue, 2 Feb 2016 03:06:29 +0000 Subject: [PATCH] Fixed null subheadings and null message cases for print.xtableList git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@110 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/R/xtableList.R | 59 ++++++++++++++++++++++----- pkg/vignettes/listOfTablesGallery.Rnw | 35 ++++++++++++++++ 2 files changed, 84 insertions(+), 10 deletions(-) diff --git a/pkg/R/xtableList.R b/pkg/R/xtableList.R index 9c7a602..f4476a3 100644 --- a/pkg/R/xtableList.R +++ b/pkg/R/xtableList.R @@ -110,8 +110,20 @@ print.xtableList <- function(x, dim(combined)[1])) command <- sapply(x, attr, "subheading") - add.to.row$command[1:length(x)] <- - paste0(mRule,"\n\\multicolumn{", nCols, "}{l}{", command, "}\\\\\n") + for (i in 1:length(x)){ + if( !is.null(command[[i]]) ){ + add.to.row$command[i] <- + paste0(mRule,"\n\\multicolumn{", nCols, "}{l}{", + command[[i]], + "}\\\\\n") + } else { + add.to.row$command[i] <- paste0(mRule, "\n") + } + } + ## Changed at request of Russ Lenth + ## add.to.row$command[1:length(x)] <- + ## paste0(mRule,"\n\\multicolumn{", nCols, "}{l}{", command, "}\\\\\n") + if ( (booktabs) & length(attr(x, "message") > 0) ){ attr(x, "message")[1] <- paste0("\\rule{0em}{2.5ex}", attr(x, "message")[1]) @@ -146,15 +158,42 @@ print.xtableList <- function(x, add.to.row <- list(pos = NULL, command = NULL) add.to.row$pos <- as.list(c(0, c(combinedRowNums[1:length(x)]))) command <- sapply(x, attr, "subheading") + + add.to.row$command[1] <- - paste0("\n\\multicolumn{", nCols, "}{l}{", command[1], "}", " \\\\ \n", - colHead) - add.to.row$command[2:length(x)] <- - paste0(bRule, - "\\\\ \n\\multicolumn{", nCols, "}{l}{", - command[2:length(x)], "}", - "\\\\ \n", - colHead) + if( !is.null(command[[1]]) ){ + add.to.row$command[1] <- + paste0("\n\\multicolumn{", nCols, "}{l}{", + command[[1]], + "}\\\\ \n", colHead, "\n") + } else { + add.to.row$command[1] <- colHead + } + + for (i in 2:length(x)) { + add.to.row$command[i] <- + if( !is.null(command[[i]]) ) { + paste0(bRule, + "\\\\ \n\\multicolumn{", nCols, "}{l}{", + command[[i]], "}", + "\\\\ \n", + colHead) + } else { + add.to.row$command[i] <- paste0("\n", colHead) + } + } + + ## Changed at request of Russ Lenth + ## add.to.row$command[1] <- + ## paste0("\n\\multicolumn{", nCols, "}{l}{", command[1], + ## "}", " \\\\ \n", + ## colHead) + ## add.to.row$command[2:length(x)] <- + ## paste0(bRule, + ## "\\\\ \n\\multicolumn{", nCols, "}{l}{", + ## command[2:length(x)], "}", + ## "\\\\ \n", + ## colHead) if ( (booktabs) & length(attr(x, "message") > 0) ){ attr(x, "message")[1] <- paste0("\\rule{0em}{2.5ex}", attr(x, "message")[1]) diff --git a/pkg/vignettes/listOfTablesGallery.Rnw b/pkg/vignettes/listOfTablesGallery.Rnw index 468cc9d..5d20236 100644 --- a/pkg/vignettes/listOfTablesGallery.Rnw +++ b/pkg/vignettes/listOfTablesGallery.Rnw @@ -92,6 +92,20 @@ xList2 <- xtableList(mtcarsList, digits = c(0,2,0,0,0,1,2), str(xList2) @ %def +Further versions with no subheadings, and no message + +<>= +attr(mtcarsList, "subheadings") <- NULL +xList3 <- xtableList(mtcarsList) +str(xList3) +@ %def + +<>= +attr(mtcarsList, "message") <- NULL +xList4 <- xtableList(mtcarsList) +str(xList4) +@ %def + \newpage \section{Single Column Names} @@ -154,6 +168,17 @@ Rotated column names? print.xtableList(xList, rotate.colnames = TRUE) @ %def +No subheadings? +<>= +print.xtableList(xList3) +@ %def + +No message? +<>= +print.xtableList(xList4) +@ %def + + \section{Multiple Column Names} \label{sec:multiple-column-names} @@ -195,6 +220,16 @@ print.xtableList(xList, colnames.format = "multiple", rotate.colnames = TRUE) @ %def +No subheadings? +<>= +print.xtableList(xList3, colnames.format = "multiple") +@ %def + +No message? +<>= +print.xtableList(xList4, colnames.format = "multiple") +@ %def + \section{lsmeans} \label{sec:lsmeans} -- 2.39.5