]> git.donarmstrong.com Git - xtable.git/commitdiff
Added sanitization of subheadings and of message in print.xtableList
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Fri, 8 Jan 2016 04:21:44 +0000 (04:21 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Fri, 8 Jan 2016 04:21:44 +0000 (04:21 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@84 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/R/xtableList.R
pkg/vignettes/listOfTablesGallery.Rnw

index d49700c6162e0b2626b14e8b9916991884bbadf6..10b2f26b2684beab28ddaa216a261d0385af58b6 100644 (file)
@@ -54,6 +54,12 @@ print.xtableList <- function(x,
                                          sanitize.text.function),\r
   sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",\r
                                          sanitize.text.function),\r
+  sanitize.subheadings.function =\r
+    getOption("xtable.sanitize.subheadings.function",\r
+              sanitize.text.function),\r
+  sanitize.message.function =\r
+    getOption("xtable.sanitize.message.function",\r
+              sanitize.text.function),\r
   math.style.negative = getOption("xtable.math.style.negative", FALSE),\r
   html.table.attributes = getOption("xtable.html.table.attributes", "border=1"),\r
   print.results = getOption("xtable.print.results", TRUE),\r
@@ -84,7 +90,21 @@ print.xtableList <- function(x,
       mRule <- "\\hline"\r
       bRule <- "\\hline"\r
     }\r
+    ## Sanitize subheadings if required\r
+    if (!is.null(sanitize.subheadings.function)) {\r
+      for (i in 1:length(x)){\r
+        attr(x[[i]], 'subheading') <-\r
+          sanitize.subheadings.function(attr(x[[i]], 'subheading'))\r
+      }\r
+    }\r
+    ## Sanitize message if required\r
+    if (!is.null(sanitize.message.function)) {\r
+      xMessage <- attr(x, 'message')\r
+      xMessage <- sapply(xMessage, sanitize.message.function)\r
+      attr(x, 'message') <- xMessage\r
+    }    \r
     if (colnames.format == "single"){\r
\r
       add.to.row <- list(pos = NULL, command = NULL)\r
       add.to.row$pos <- as.list(c(0, combinedRowNums[-length(x)],\r
                                   dim(combined)[1]))\r
index e32d2835dbc907d47ee4d817be21bf5f9c544fa1..468cc9d16fa60ae992f65eda1dde94e0d8b1c763 100644 (file)
@@ -117,7 +117,7 @@ With digits being specified.
 print.xtableList(xList1, booktabs = TRUE)\r
 @ %def\r
 \r
-Row and column names can be sanitized.\r
+Row and column names, subheadings, and the message can be sanitized.\r
 \r
 <<sanitize>>=\r
 large <- function(x){\r
@@ -126,6 +126,12 @@ large <- function(x){
 italic <- function(x){\r
   paste0('{\\emph{ ', x, '}}')\r
 }\r
+bold <- function(x){\r
+  paste0('{\\bfseries ', x, '}')\r
+}\r
+red <- function(x){\r
+  paste0('{\\color{red} ', x, '}')\r
+}\r
 @ %def\r
 \r
 \r
@@ -133,6 +139,8 @@ italic <- function(x){
 print.xtableList(xList,\r
                  sanitize.rownames.function = italic,\r
                  sanitize.colnames.function = large,\r
+                 sanitize.subheadings.function = bold,\r
+                 sanitize.message.function = red,\r
                  booktabs = TRUE)\r
 @ %def\r
 \r
@@ -170,6 +178,8 @@ With sanitization.
 print.xtableList(xList, colnames.format = "multiple",\r
                  sanitize.rownames.function = italic,\r
                  sanitize.colnames.function = large,\r
+                 sanitize.subheadings.function = bold,\r
+                 sanitize.message.function = red,                 \r
                  booktabs = TRUE)\r
 @ %def\r
 \r