}
-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)
}
}
--- /dev/null
+\name{sanitize}\r
+\alias{sanitize}\r
+\alias{sanitize.numbers}\r
+\alias{sanitize.final}\r
+\r
+\title{\r
+ Sanitization Functions\r
+}\r
+\description{\r
+ Functions for sanitizing elements of a table produced by\r
+ \pkg{xtable}. Used for dealing with characters which have special\r
+ meaning in the output format.\r
+}\r
+\usage{\r
+sanitize(str, type)\r
+sanitize.numbers(str, type, math.style.negative)\r
+sanitize.final(str, type)\r
+}\r
+\r
+\arguments{\r
+ \item{str}{A character object to be sanitized.}\r
+ \item{type}{Type of table to produce. Possible values for \code{type}\r
+ are \code{"latex"} or \code{"html"}.\r
+ Default value is \code{"latex"}.}\r
+ \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use\r
+ $-$ for the negative sign (as was the behavior prior to version 1.5-3).\r
+ Default value is \code{FALSE}.}\r
+}\r
+\details{\r
+\r
+ If \code{type} is \code{"latex"}, \code{sanitize()} will replace\r
+ special characters such as \verb{&} and the like by strings which will\r
+ reproduce the actual character, e.g. \verb{&} is replaced by\r
+ \verb{\\&}.\r
+\r
+ If \code{type} is \code{"html"}, \code{sanitize()} will replace\r
+ special characters such as \verb{<} and the like by strings which will\r
+ reproduce the actual character, e.g. \verb{<} is replaced by\r
+ \verb{<}.\r
+\r
+ When \code{math.style.negative} is \code{TRUE}, and \code{type} is\r
+ \code{"latex"}, $-$ is used for the negative sign rather than a\r
+ simple hyphen (-). No effect when \code{type} is \code{"html"}.\r
+\r
+ When \code{type} is \code{"latex"} \code{sanitize.final} has no\r
+ effect. When \code{type} is \code{"html"}, multiple spaces are\r
+ replaced by a single space and occurrences of \code{' align="left"'}\r
+ are eliminated.\r
+}\r
+\value{\r
+ Returns the sanitized character object.\r
+}\r
+\r
+\author{\r
+ Code was extracted from \code{print.xtable()}, in version 1.8.0 of\r
+ \pkg{xtable}. Various authors contributed the original code: Jonathan\r
+ Swinton <jonathan@swintons.net>, Uwe Ligges\r
+ <ligges@statistik.uni-dortmund.de>, and probably David B. Dahl\r
+ <dahl@stat.byu.edu>.\r
+}\r
+\r
+\examples{\r
+\r
+insane <- c("&",">", ">","_","\%","$","\\\\","#","^","~","{","}")\r
+names(insane) <- c("Ampersand","Greater than","Less than",\r
+ "Underscore","Percent","Dollar",\r
+ "Backslash","Hash","Caret","Tilde",\r
+ "Left brace","Right brace")\r
+sanitize(insane, type = "latex")\r
+insane <- c("&",">","<")\r
+names(insane) <- c("Ampersand","Greater than","Less than")\r
+sanitize(insane, type = "html")\r
+x <- rnorm(10)\r
+sanitize.numbers(x, "latex", TRUE)\r
+sanitize.numbers(x, "html", TRUE)\r
+}\r
+\r
+\keyword{print }\r