]> git.donarmstrong.com Git - xtable.git/blob - pkg/man/sanitize.Rd
3bba1072e6ee4b31800932c0833a75aae2c8ca63
[xtable.git] / pkg / man / sanitize.Rd
1 \name{sanitize}\r
2 \alias{sanitize}\r
3 \alias{sanitize.numbers}\r
4 \alias{sanitize.final}\r
5 \r
6 \title{\r
7   Sanitization Functions\r
8 }\r
9 \description{\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
13 }\r
14 \usage{\r
15 sanitize(str, type)\r
16 sanitize.numbers(str, type, math.style.negative = FALSE,\r
17                  math.style.exponents = FALSE)\r
18 sanitize.final(str, type)\r
19 }\r
20 \r
21 \arguments{\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
35 }\r
36 \details{\r
37 \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
41   \verb{\\&}.\r
42 \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
46   \verb{&lt;}.\r
47 \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
51 \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
57 \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
61   are eliminated.\r
62 }\r
63 \value{\r
64   Returns the sanitized character object.\r
65 }\r
66 \r
67 \author{\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
73 }\r
74 \r
75 \examples{\r
76 \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
86 x <- rnorm(10)\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
90 }\r
91 \r
92 \keyword{print }\r