]> git.donarmstrong.com Git - xtable.git/blob - pkg/man/sanitize.Rd
Fixed default of sanitize type argument to be 'latex' as specified in the docs
[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 \alias{as.is}\r
6 \alias{as.math}\r
7 \r
8 \title{\r
9   Sanitization Functions\r
10 }\r
11 \description{\r
12   Functions for sanitizing elements of a table produced by\r
13   \pkg{xtable}. Used for dealing with characters which have special\r
14   meaning in the output format.\r
15 }\r
16 \usage{\r
17 sanitize(str, type = "latex")\r
18 sanitize.numbers(str, type, math.style.negative = FALSE,\r
19                  math.style.exponents = FALSE)\r
20 sanitize.final(str, type)\r
21 as.is(str)\r
22 as.math(str, ...)\r
23 }\r
24 \r
25 \arguments{\r
26   \item{str}{A character object to be sanitized.}\r
27   \item{type}{Type of table to produce. Possible values for \code{type}\r
28     are \code{"latex"} or \code{"html"}.\r
29     Default value is \code{"latex"}.}\r
30   \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use\r
31     $-$ for the negative sign (as was the behavior prior to version 1.5-3).\r
32     Default value is \code{FALSE}.}\r
33   \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or\r
34     \code{"$$"}, then use \verb{$5 \times 10^{5}$} for 5e5. If\r
35     \code{"ensuremath"}, then use \verb{\ensuremath{5 \times 10^{5}}}\r
36     for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to\r
37     approximate the LaTeX typsetting for 5e5.\r
38     Default value is \code{FALSE}.}\r
39   \item{\dots}{Additional arguments. Character strings or character\r
40     vectors.}\r
41 }\r
42 \details{\r
43 \r
44   If \code{type} is \code{"latex"}, \code{sanitize()} will replace\r
45   special characters such as \verb{&} and the like by strings which will\r
46   reproduce the actual character, e.g. \verb{&} is replaced by\r
47   \verb{\\&}.\r
48 \r
49   If \code{type} is \code{"html"}, \code{sanitize()} will replace\r
50   special characters such as \verb{<} and the like by strings which will\r
51   reproduce the actual character, e.g. \verb{<} is replaced by\r
52   \verb{&lt;}.\r
53 \r
54   When \code{math.style.negative} is \code{TRUE}, and \code{type} is\r
55   \code{"latex"}, $-$ is used for the negative sign rather than a\r
56   simple hyphen (-). No effect when \code{type} is \code{"html"}.\r
57 \r
58   When \code{type} is \code{"latex"}, and \code{math.style.exponents}\r
59   is \code{TRUE} or \verb{"$$"}, then use \verb{$5 \times 10^{5}$} for\r
60   5e5. If \code{"ensuremath"}, then use \verb{\ensuremath{5 \times\r
61   10^{5}}} for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8\r
62   to approximate the LaTeX typsetting for 5e5.\r
63 \r
64   When \code{type} is \code{"latex"} \code{sanitize.final} has no\r
65   effect. When \code{type} is \code{"html"}, multiple spaces are\r
66   replaced by a single space and occurrences of \code{' align="left"'}\r
67   are eliminated.\r
68 \r
69   \code{as.is} and \code{as.math} are trivial helper functions to\r
70   disable sanitizing and to insert a some mathematics in a string\r
71   respectively.\r
72 }\r
73 \value{\r
74   Returns the sanitized character object.\r
75 }\r
76 \r
77 \author{\r
78   Code was extracted from \code{print.xtable()}, in version 1.8.0 of\r
79   \pkg{xtable}. Various authors contributed the original code: Jonathan\r
80   Swinton <jonathan@swintons.net>, Uwe Ligges\r
81   <ligges@statistik.uni-dortmund.de>, and probably David B. Dahl\r
82   <dahl@stat.byu.edu>.\r
83   \code{as.is} and \code{as.math} suggested and provided by Stefan\r
84   Edwards <sme@iysik.com>.\r
85 }\r
86 \r
87 \examples{\r
88 insane <- c("&",">", ">","_","\%","$","\\\\","#","^","~","{","}")\r
89 names(insane) <- c("Ampersand","Greater than","Less than",\r
90                    "Underscore","Percent","Dollar",\r
91                    "Backslash","Hash","Caret","Tilde",\r
92                    "Left brace","Right brace")\r
93 sanitize(insane, type = "latex")\r
94 insane <- c("&",">","<")\r
95 names(insane) <- c("Ampersand","Greater than","Less than")\r
96 sanitize(insane, type = "html")\r
97 x <- rnorm(10)\r
98 sanitize.numbers(x, "latex", TRUE)\r
99 sanitize.numbers(x*10^(10), "latex", TRUE, TRUE)\r
100 sanitize.numbers(x, "html", TRUE, TRUE)\r
101 as.is(insane)\r
102 as.math("x10^10", ": mathematical expression")\r
103 }\r
104 \r
105 \keyword{print }\r