3 \alias{sanitize.numbers}
\r
4 \alias{sanitize.final}
\r
7 Sanitization Functions
\r
10 Functions for sanitizing elements of a table produced by
\r
11 \pkg{xtable}. Used for dealing with characters which have special
\r
12 meaning in the output format.
\r
16 sanitize.numbers(str, type, math.style.negative = FALSE,
\r
17 math.style.exponents = FALSE)
\r
18 sanitize.final(str, type)
\r
22 \item{str}{A character object to be sanitized.}
\r
23 \item{type}{Type of table to produce. Possible values for \code{type}
\r
24 are \code{"latex"} or \code{"html"}.
\r
25 Default value is \code{"latex"}.}
\r
26 \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use
\r
27 $-$ for the negative sign (as was the behavior prior to version 1.5-3).
\r
28 Default value is \code{FALSE}.}
\r
29 \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or
\r
30 \code{"$$"}, then use \verb{$5 \times 10^{5}$} for 5e5. If
\r
31 \code{"ensuremath"}, then use \verb{\ensuremath{5 \times 10^{5}}}
\r
32 for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to
\r
33 approximate the LaTeX typsetting for 5e5.
\r
34 Default value is \code{FALSE}.}
\r
38 If \code{type} is \code{"latex"}, \code{sanitize()} will replace
\r
39 special characters such as \verb{&} and the like by strings which will
\r
40 reproduce the actual character, e.g. \verb{&} is replaced by
\r
43 If \code{type} is \code{"html"}, \code{sanitize()} will replace
\r
44 special characters such as \verb{<} and the like by strings which will
\r
45 reproduce the actual character, e.g. \verb{<} is replaced by
\r
48 When \code{math.style.negative} is \code{TRUE}, and \code{type} is
\r
49 \code{"latex"}, $-$ is used for the negative sign rather than a
\r
50 simple hyphen (-). No effect when \code{type} is \code{"html"}.
\r
52 When \code{type} is \code{"latex"}, and \code{math.style.exponents}
\r
53 is \code{TRUE} or \verb{"$$"}, then use \verb{$5 \times 10^{5}$} for
\r
54 5e5. If \code{"ensuremath"}, then use \verb{\ensuremath{5 \times
\r
55 10^{5}}} for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8
\r
56 to approximate the LaTeX typsetting for 5e5.
\r
58 When \code{type} is \code{"latex"} \code{sanitize.final} has no
\r
59 effect. When \code{type} is \code{"html"}, multiple spaces are
\r
60 replaced by a single space and occurrences of \code{' align="left"'}
\r
64 Returns the sanitized character object.
\r
68 Code was extracted from \code{print.xtable()}, in version 1.8.0 of
\r
69 \pkg{xtable}. Various authors contributed the original code: Jonathan
\r
70 Swinton <jonathan@swintons.net>, Uwe Ligges
\r
71 <ligges@statistik.uni-dortmund.de>, and probably David B. Dahl
\r
72 <dahl@stat.byu.edu>.
\r
77 insane <- c("&",">", ">","_","\%","$","\\\\","#","^","~","{","}")
\r
78 names(insane) <- c("Ampersand","Greater than","Less than",
\r
79 "Underscore","Percent","Dollar",
\r
80 "Backslash","Hash","Caret","Tilde",
\r
81 "Left brace","Right brace")
\r
82 sanitize(insane, type = "latex")
\r
83 insane <- c("&",">","<")
\r
84 names(insane) <- c("Ampersand","Greater than","Less than")
\r
85 sanitize(insane, type = "html")
\r
87 sanitize.numbers(x, "latex", TRUE)
\r
88 sanitize.numbers(x*10^(10), "latex", TRUE, TRUE)
\r
89 sanitize.numbers(x, "html", TRUE, TRUE)
\r