]> git.donarmstrong.com Git - xtable.git/commitdiff
Added documentation for sanitize functions
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Sat, 9 Jan 2016 03:02:59 +0000 (03:02 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Sat, 9 Jan 2016 03:02:59 +0000 (03:02 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@85 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/R/sanitize.R
pkg/man/print.xtable.Rd
pkg/man/sanitize.Rd [new file with mode: 0644]
pkg/man/string.Rd
pkg/man/xtable-internal.Rd

index 92441fd27358fbecb09cad5a46dffce0c83fe4a8..1313a96a4e2f89199907e8ae5f460f10c16b4c0a 100644 (file)
@@ -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)
   }
 }
index d4cccb0a6903b714c7fcc3fdb14a9cc98e9a5736..6f82b7220a67835193bb54d957f8e5b2b3b3ad12 100644 (file)
@@ -44,7 +44,7 @@
   ...)}\r
 \arguments{\r
   \item{x}{An object of class \code{"xtable"}.}\r
-  \item{type}{Type of table to produce.  Possible values for \code{type}\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{file}{Name of file where the resulting code should be saved.  If\r
diff --git a/pkg/man/sanitize.Rd b/pkg/man/sanitize.Rd
new file mode 100644 (file)
index 0000000..aa46247
--- /dev/null
@@ -0,0 +1,78 @@
+\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{&lt;}.\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
index c117fcf6c68d8b78776d9a7315deffcfd9b2f053..88e9d2f9036b4d6a28cddd9b0f334402bf094302 100644 (file)
@@ -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}
index 00df62f84974dbffed05d8a803c65ccd14e73270..1e0bd4dec7d1b6e7c82d242ef2306c16ba4befd5 100644 (file)
@@ -3,9 +3,6 @@
 \alias{xtableList}\r
 \alias{print.xtableList}\r
 \alias{xtableLSMeans}\r
-\alias{sanitize}\r
-\alias{sanitize.numbers}\r
-\alias{sanitize.final}\r
 \r
 \title{Internal xtable Functions}\r
 \description{\r