From: dscott Date: Sat, 9 Jan 2016 03:02:59 +0000 (+0000) Subject: Added documentation for sanitize functions X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;ds=sidebyside;h=252ab878b5e1c518fc9655d168a954e537e5825d;p=xtable.git Added documentation for sanitize functions git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@85 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- diff --git a/pkg/R/sanitize.R b/pkg/R/sanitize.R index 92441fd..1313a96 100644 --- a/pkg/R/sanitize.R +++ b/pkg/R/sanitize.R @@ -26,28 +26,28 @@ sanitize <- function(str, type) { } -sanitize.numbers <- function(x, type, math.style.negative){ +sanitize.numbers <- function(str, type, math.style.negative){ if (type == "latex"){ - result <- x + result <- str if ( math.style.negative ) { - for(i in 1:length(x)) { + for(i in 1:length(str)) { result[i] <- gsub("-", "$-$", result[i], fixed = TRUE) } } return(result) } else { - return(x) + return(str) } } -sanitize.final <- function(result, type){ +sanitize.final <- function(str, type){ if (type == "latex"){ - return(result) + return(str) } else { - result$text <- gsub(" *", " ", result$text, fixed = TRUE) - result$text <- gsub(' align="left"', "", result$text, + str$text <- gsub(" *", " ", str$text, fixed = TRUE) + str$text <- gsub(' align="left"', "", str$text, fixed = TRUE) - return(result) + return(str) } } diff --git a/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd index d4cccb0..6f82b72 100644 --- a/pkg/man/print.xtable.Rd +++ b/pkg/man/print.xtable.Rd @@ -44,7 +44,7 @@ ...)} \arguments{ \item{x}{An object of class \code{"xtable"}.} - \item{type}{Type of table to produce. Possible values for \code{type} + \item{type}{Type of table to produce. Possible values for \code{type} are \code{"latex"} or \code{"html"}. Default value is \code{"latex"}.} \item{file}{Name of file where the resulting code should be saved. If diff --git a/pkg/man/sanitize.Rd b/pkg/man/sanitize.Rd new file mode 100644 index 0000000..aa46247 --- /dev/null +++ b/pkg/man/sanitize.Rd @@ -0,0 +1,78 @@ +\name{sanitize} +\alias{sanitize} +\alias{sanitize.numbers} +\alias{sanitize.final} + +\title{ + Sanitization Functions +} +\description{ + Functions for sanitizing elements of a table produced by + \pkg{xtable}. Used for dealing with characters which have special + meaning in the output format. +} +\usage{ +sanitize(str, type) +sanitize.numbers(str, type, math.style.negative) +sanitize.final(str, type) +} + +\arguments{ + \item{str}{A character object to be sanitized.} + \item{type}{Type of table to produce. Possible values for \code{type} + are \code{"latex"} or \code{"html"}. + Default value is \code{"latex"}.} + \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use + $-$ for the negative sign (as was the behavior prior to version 1.5-3). + Default value is \code{FALSE}.} +} +\details{ + + If \code{type} is \code{"latex"}, \code{sanitize()} will replace + special characters such as \verb{&} and the like by strings which will + reproduce the actual character, e.g. \verb{&} is replaced by + \verb{\\&}. + + If \code{type} is \code{"html"}, \code{sanitize()} will replace + special characters such as \verb{<} and the like by strings which will + reproduce the actual character, e.g. \verb{<} is replaced by + \verb{<}. + + When \code{math.style.negative} is \code{TRUE}, and \code{type} is + \code{"latex"}, $-$ is used for the negative sign rather than a + simple hyphen (-). No effect when \code{type} is \code{"html"}. + + When \code{type} is \code{"latex"} \code{sanitize.final} has no + effect. When \code{type} is \code{"html"}, multiple spaces are + replaced by a single space and occurrences of \code{' align="left"'} + are eliminated. +} +\value{ + Returns the sanitized character object. +} + +\author{ + Code was extracted from \code{print.xtable()}, in version 1.8.0 of + \pkg{xtable}. Various authors contributed the original code: Jonathan + Swinton , Uwe Ligges + , and probably David B. Dahl + . +} + +\examples{ + +insane <- c("&",">", ">","_","\%","$","\\\\","#","^","~","{","}") +names(insane) <- c("Ampersand","Greater than","Less than", + "Underscore","Percent","Dollar", + "Backslash","Hash","Caret","Tilde", + "Left brace","Right brace") +sanitize(insane, type = "latex") +insane <- c("&",">","<") +names(insane) <- c("Ampersand","Greater than","Less than") +sanitize(insane, type = "html") +x <- rnorm(10) +sanitize.numbers(x, "latex", TRUE) +sanitize.numbers(x, "html", TRUE) +} + +\keyword{print } diff --git a/pkg/man/string.Rd b/pkg/man/string.Rd index c117fcf..88e9d2f 100644 --- a/pkg/man/string.Rd +++ b/pkg/man/string.Rd @@ -25,6 +25,9 @@ These functions are private functions used by \code{print.xtable}. They are not intended to be used elsewhere. } -\author{David Dahl \email{dahl@stat.byu.edu} with contributions and suggestions from many others (see source code).} +\author{ + David Dahl \email{dahl@stat.byu.edu} with contributions and + suggestions from many others (see source code). +} \seealso{\code{\link{print.xtable}}} \keyword{print} diff --git a/pkg/man/xtable-internal.Rd b/pkg/man/xtable-internal.Rd index 00df62f..1e0bd4d 100644 --- a/pkg/man/xtable-internal.Rd +++ b/pkg/man/xtable-internal.Rd @@ -3,9 +3,6 @@ \alias{xtableList} \alias{print.xtableList} \alias{xtableLSMeans} -\alias{sanitize} -\alias{sanitize.numbers} -\alias{sanitize.final} \title{Internal xtable Functions} \description{