From 5c7308041ef87fb203a3bade2236ee8e5f8b9260 Mon Sep 17 00:00:00 2001 From: dscott Date: Fri, 8 Jan 2016 04:21:44 +0000 Subject: [PATCH] Added sanitization of subheadings and of message in print.xtableList git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@84 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- pkg/R/xtableList.R | 20 ++++++++++++++++++++ pkg/vignettes/listOfTablesGallery.Rnw | 12 +++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pkg/R/xtableList.R b/pkg/R/xtableList.R index d49700c..10b2f26 100644 --- a/pkg/R/xtableList.R +++ b/pkg/R/xtableList.R @@ -54,6 +54,12 @@ print.xtableList <- function(x, sanitize.text.function), sanitize.colnames.function = getOption("xtable.sanitize.colnames.function", sanitize.text.function), + sanitize.subheadings.function = + getOption("xtable.sanitize.subheadings.function", + sanitize.text.function), + sanitize.message.function = + getOption("xtable.sanitize.message.function", + sanitize.text.function), math.style.negative = getOption("xtable.math.style.negative", FALSE), html.table.attributes = getOption("xtable.html.table.attributes", "border=1"), print.results = getOption("xtable.print.results", TRUE), @@ -84,7 +90,21 @@ print.xtableList <- function(x, mRule <- "\\hline" bRule <- "\\hline" } + ## Sanitize subheadings if required + if (!is.null(sanitize.subheadings.function)) { + for (i in 1:length(x)){ + attr(x[[i]], 'subheading') <- + sanitize.subheadings.function(attr(x[[i]], 'subheading')) + } + } + ## Sanitize message if required + if (!is.null(sanitize.message.function)) { + xMessage <- attr(x, 'message') + xMessage <- sapply(xMessage, sanitize.message.function) + attr(x, 'message') <- xMessage + } if (colnames.format == "single"){ + add.to.row <- list(pos = NULL, command = NULL) add.to.row$pos <- as.list(c(0, combinedRowNums[-length(x)], dim(combined)[1])) diff --git a/pkg/vignettes/listOfTablesGallery.Rnw b/pkg/vignettes/listOfTablesGallery.Rnw index e32d283..468cc9d 100644 --- a/pkg/vignettes/listOfTablesGallery.Rnw +++ b/pkg/vignettes/listOfTablesGallery.Rnw @@ -117,7 +117,7 @@ With digits being specified. print.xtableList(xList1, booktabs = TRUE) @ %def -Row and column names can be sanitized. +Row and column names, subheadings, and the message can be sanitized. <>= large <- function(x){ @@ -126,6 +126,12 @@ large <- function(x){ italic <- function(x){ paste0('{\\emph{ ', x, '}}') } +bold <- function(x){ + paste0('{\\bfseries ', x, '}') +} +red <- function(x){ + paste0('{\\color{red} ', x, '}') +} @ %def @@ -133,6 +139,8 @@ italic <- function(x){ print.xtableList(xList, sanitize.rownames.function = italic, sanitize.colnames.function = large, + sanitize.subheadings.function = bold, + sanitize.message.function = red, booktabs = TRUE) @ %def @@ -170,6 +178,8 @@ With sanitization. print.xtableList(xList, colnames.format = "multiple", sanitize.rownames.function = italic, sanitize.colnames.function = large, + sanitize.subheadings.function = bold, + sanitize.message.function = red, booktabs = TRUE) @ %def -- 2.39.5