| Line 1... |
Line 1... |
| 1 |
\name{encodeString}
|
1 |
\name{encodeString}
|
| 2 |
\alias{encodeString}
|
2 |
\alias{encodeString}
|
| - |
|
3 |
\title{
|
| 3 |
\title{ Encode Character Vector as for Printing }
|
4 |
Encode Character Vector as for Printing
|
| - |
|
5 |
}
|
| 4 |
\description{
|
6 |
\description{
|
| 5 |
\code{encodeString} escapes the strings in a character vector in the
|
7 |
\code{encodeString} escapes the strings in a character vector in the
|
| 6 |
same way \code{print.default} does, and optionally fits the encoded
|
8 |
same way \code{print.default} does, and optionally fits the encoded
|
| 7 |
string within a field width.
|
9 |
strings within a field width.
|
| 8 |
}
|
10 |
}
|
| 9 |
\usage{
|
11 |
\usage{
|
| 10 |
encodeString(x, w = 0, quote = "", right = FALSE, na = TRUE)
|
12 |
encodeString(x, w = 0, quote = "", na = TRUE,
|
| - |
|
13 |
justify = c("left", "right", "centre"))
|
| 11 |
}
|
14 |
}
|
| 12 |
\arguments{
|
15 |
\arguments{
|
| 13 |
\item{x}{A character vector, or an object that can be coerced to one
|
16 |
\item{x}{A character vector, or an object that can be coerced to one
|
| 14 |
by \code{\link{as.character}}.}
|
17 |
by \code{\link{as.character}}.}
|
| 15 |
\item{w}{integer: the minimum field width.}
|
18 |
\item{w}{integer: the minimum field width. If \code{NA}, this is
|
| - |
|
19 |
taken to be the largest field width needed for any element of \code{x}.}
|
| 16 |
\item{quote}{character: quoting character, if any.}
|
20 |
\item{quote}{character: quoting character, if any.}
|
| 17 |
\item{right}{logical: if the escaped string is shorter than \code{w}
|
- |
|
| 18 |
characters, should it be left or right justified (by padding with
|
- |
|
| 19 |
spaces)?}
|
- |
|
| 20 |
\item{na}{logical: should \code{NA} strings be encoded?}
|
21 |
\item{na}{logical: should \code{NA} strings be encoded?}
|
| - |
|
22 |
\item{justify}{character: partial matches are allowed. If padding to
|
| - |
|
23 |
the minimum field width is needed, how should spaces be inserted?}
|
| 21 |
}
|
24 |
}
|
| 22 |
\details{
|
25 |
\details{
|
| 23 |
This escapes the control characters \code{\a} (bell), \code{\b}
|
26 |
This escapes backslash and the control characters \code{\a} (bell),
|
| 24 |
(backspace), \code{\f} (formfeed), \code{\n} (line feed), \code{\r}
|
27 |
\code{\b} (backspace), \code{\f} (formfeed), \code{\n} (line feed),
|
| 25 |
(carriage return), \code{\t} (tab), \code{\v} (vertical tab) and
|
28 |
\code{\r} (carriage return), \code{\t} (tab), \code{\v} (vertical tab)
|
| 26 |
\code{\0} (nul) as well as backslash and non-printable characters,
|
29 |
and \code{\0} (nul) as well as any non-printable characters, which are
|
| 27 |
which are printed in octal notation (\code{\xyz} with leading zeroes).
|
30 |
printed in octal notation (\code{\xyz} with leading zeroes).
|
| 28 |
#ifdef unix
|
31 |
#ifdef unix
|
| 29 |
(Which characters are non-printable depends on the current locale.)
|
32 |
(Which characters are non-printable depends on the current locale.)
|
| 30 |
#endif
|
33 |
#endif
|
| 31 |
#ifdef windows
|
34 |
#ifdef windows
|
| 32 |
(Windows is unreliable, so all other control characters are regarded
|
35 |
(Windows' reporting of printable characters is unreliable, so all
|
| - |
|
36 |
other control characters are regarded as non-printable, and all
|
| 33 |
as non-printable, and all characters with codes 32--255 as printable.)
|
37 |
characters with codes 32--255 as printable.)
|
| 34 |
#endif
|
38 |
#endif
|
| 35 |
|
39 |
|
| 36 |
If \code{quote} is a single or double quote any embedded quote of the
|
40 |
If \code{quote} is a single or double quote any embedded quote of the
|
| 37 |
same type is escaped.
|
41 |
same type is escaped. Note that justification is of the quoted
|
| - |
|
42 |
string, hence spaces are added outside the quotes.
|
| 38 |
}
|
43 |
}
|
| 39 |
\value{
|
44 |
\value{
|
| 40 |
A character vector of the same length as \code{x}, with the same attributes.
|
45 |
A character vector of the same length as \code{x}, with the same
|
| - |
|
46 |
attributes (including names and dimensions).
|
| 41 |
}
|
47 |
}
|
| 42 |
\seealso{
|
48 |
\seealso{
|
| 43 |
\code{\link{print.default}}
|
49 |
\code{\link{print.default}}
|
| 44 |
}
|
50 |
}
|
| 45 |
\examples{
|
51 |
\examples{
|
| Line 47... |
Line 53... |
| 47 |
print(x)
|
53 |
print(x)
|
| 48 |
cat(x) # interprets escapes
|
54 |
cat(x) # interprets escapes
|
| 49 |
cat(encodeString(x), "\n", sep="") # similar to print()
|
55 |
cat(encodeString(x), "\n", sep="") # similar to print()
|
| 50 |
|
56 |
|
| 51 |
factor(x) # makes use of this to print the levels
|
57 |
factor(x) # makes use of this to print the levels
|
| - |
|
58 |
|
| - |
|
59 |
x <- c("a", "ab", "abcde")
|
| - |
|
60 |
encodeString(x, w = NA) # left justification
|
| - |
|
61 |
encodeString(x, w = NA, justify = "c")
|
| - |
|
62 |
encodeString(x, w = NA, justify = "r")
|
| - |
|
63 |
encodeString(x, w = NA, quote = "'", justify = "r")
|
| 52 |
}
|
64 |
}
|
| 53 |
\keyword{ utilities }
|
65 |
\keyword{ utilities }
|
| 54 |
|
66 |
|